Let's say I have a data frame df
and want a subset of it based on the value of column a.
df <- data.frame(a = 1:4, b = 5:8)
df
Do I need to include a function in brackets which
or can I just include a logic test?
df[df$a == "2",]
df[which(df$a == "2"),]
Everything seems to work the same way ... I was getting some strange results in a large data frame (i.e. getting blank lines as well as correct ones), but as soon as I cleaned up the environment and restarted my script it worked fine.
source
share