You seem to have two errors, try this instead:
df[df$x>30 & df$x<40,]
# x y
# 31 31 62
# 32 32 64
# 33 33 66
# 34 34 68
# 35 35 70
# 36 36 72
# 37 37 74
# 38 38 76
# 39 39 78
Explanation:
The first error is that you are using &&
instead of &
. You want the first form if you are sure there is a comparison of vectors of length one. See this question for details.
The second one, is that you are missing a comma (","). Writing the condition for subsetting first, then a comma, then nothing, will select the rows
that satisfy this condition.
You can check the differences on subsets with that same df
when you try df[]
, df[1,]
and df[,1]
.