I'm wondering whether there is a way to compare and filter out two rows without having to first use something like the spread function. For example:
Thanks in advance!
iv <- c(1,2,3,1,2,3,1,2,3,1,2,3)
Vert <- c("Top","Top","Top","Bottom","Bottom","Bottom","Top","Top","Top","Bottom","Bottom","Bottom")
Horiz <- c("Left", "Left", "Left", "Left", "Left", "Left", "Right", "Right", "Right", "Right", "Right", "Right")
dv <- c(.7,.8,.8,.8,.7,.9,.6,.6,.6,.25,.5,.75)
mydf <- data.frame(iv, Vert, Horiz, dv)
mydf %>%
spread(Vert, dv) %>%
filter(Top > Bottom) %>%
gather(Vert, dv, -Horiz, -iv)
iv Horiz Vert dv
# 1 1 Right Bottom 0.25
# 2 2 Left Bottom 0.70
# 3 2 Right Bottom 0.50
# 4 1 Right Top 0.60
# 5 2 Left Top 0.80
# 6 2 Right Top 0.60
mydf %>%
group_by(iv, Vert) %>% # maybe something with similar logic?
filter(Top > Bottom)
# Error: object 'Top' not found