I have this framework:
df1 <- data.frame(a = c("correct", "wrong", "wrong", "correct"), b = c(1, 2, 3, 4), c = c("wrong", "wrong", "wrong", "wrong"), d = c(2, 2, 3, 4)) abcd correct 1 wrong 2 wrong 2 wrong 2 wrong 3 wrong 3 correct 4 wrong 4
and would like to select only the columns with the rows “right” or “wrong” (that is, columns b and d in df1), so that I get this data frame:
df2 <- data.frame(a = c("correct", "wrong", "wrong", "correct"), c = c("wrong", "wrong", "wrong", "wrong")) ac 1 correct wrong 2 wrong wrong 3 wrong wrong 4 correct wrong
Can dplyr be used for this? If not, what features can I use for this? The example I gave is simple, as I can just do it (dplyr):
select(df1, a, c)
However, in my actual frame, I have about 700 variables / columns and several hundred columns that contain the rows “right” or “wrong”, and I don't know the names of the variables / columns.
Any suggestions on how to do this quickly? Thank you very much!