[R] subsetting - questions

Muhuri, Pradip (SAMHSA/CBHSQ)
2012-11-24T02:55:57Z

df[df$X1>=8,] [,1:2]                   #1
df[df$X1>=8,] [,-c(3,4,5)]             #2
df[df$X1>=8,] [,c(-3,-4,-5)]           #3
df[df$X1>=8,] [,c("X1", "X2")]         #4
df[df$X1>=8,] [,-c("X3", "X4", "X5")]  #5  DOES
NOT WORK
df[df$X1>=8,] [,keep_var]              #6
df[df$X1>=8,] [, !drop_var]            #7   DOES NOT WORK