I have a few dataframes with only a few variables different from each other. Mostly they are the same. I would like to prepare the variables in a loop, so I do not have to specify each and every variable for all my dataframes separately. I'm however running into some issues.
clist <- c("data", "data_error", "data_RT")
I first made a list of the names of my dataframes
for (i in clist) {
i$ID <- as.factor(i$ID)
i$TMS <- as.factor(i$TMS)
i$bias<- as.numeric(i$bias)
... }
The I try to loop over all the variables I want to prepare. This is however not possible and I get an error message saying:
Error in i$ID : $ operator is invalid for atomic vectors
I tried google for help, but I did not understand the explanations for it :( Could you help me understand what I'm doing wrong and how I could solve it?
clist <- c(data, data_error, data_RT) for (i in clist) { i[,"ID"] <- as.factor(i[,"ID"]) }but it tells meError in[.default(i, , "ID") : incorrect number of dimensions. This confuses me, because if I just replace the "i" with "data" (as I intend the loop to do)data[,"ID"] <- as.factor(data[,"ID"]), it does work... Any thoughts on where the dimension mismatch might stem from?