I want to generate multiple data frames (df1, df2 etc.) based on one big data frame (df0). Each new data frame should consist of some mix of columns from df0.
df0 <- data.frame(v0=c(0, 0), v1=c(3, 4), v2=c(5, 6), v3=c(7, 8))
for(i in 1:3) {
secondcol <- colnames(df0[,..i]) # I get an error here
dfX = subset(df0, select = c("v0", secondcol)) # dfX should be df & i
}
# The for loop should replicate the following three comands:
df1 = subset(df0, select = c("v0", "v1"))
df2 = subset(df0, select = c("v0", "v2"))
df3 = subset(df0, select = c("v0", "v3"))