I have a data frame in R like this:
> df <- data.frame(cbind(C.01=1, C.02=1:8, C.03=c("A","B","C","D","E","F","G","H")))
And I would obtain a subset like this:
> subset(df, C.03 == "A")
C.01 C.02 C.03
1 1 1 A
It's possible do the same subset but having the name of the column in xx <- "C.03" ??
Because subset(df, xx == "A") doesn't works.
Thnks.
df[df[xx] == "A", ]subsetand use standard[and[[operators, like @DavidArenburg suggests. Alsodf[df[[xx]]=="A",]works in this case.".."subset, you could trysubset(df,eval(parse(text=paste0(xx,"==","\"A\"")))). However, this kind of hacky code ultimately eliminatessubset's main advantage of better readability. Usingsubsetmight also cause unexpected behaviour (see, e.g., stackoverflow.com/questions/9860090/…).