Im new to R, and im a bit confused!
I'm trying to get the column names of a CSV and then iterate over them and use them as a key in an linear model function.
Ive been getting errors when trying to do this by getting the column names like so:
columns <- as.list(VBPersonasMulti[0,2:length(VBPersonasMulti)])
and then referencing these as keys in the ml function
for (i in seq_along(column)) {
anal <- lm(open ~ unlist(column[i]), data = VBPersonasMulti)
}
I have tried without unlist and several other functions and also column[[i]]) a solution to the above method would be ideal, but i am also having problems with a less dynamic version of this iteration
which is creating a fixed list of the column names i really wanted to iterate over from the csv (or reassignment of that column) :
colnames <- list('attempted','open', 'completed', 'attempted', 'earned', 'commented', 'X7'
, 'logout', 'join', 'leave', 'flag_as_inaproppriate')
for (i in seq_along(colnames)) {
print(colnames[i])
anal <- lm(open ~ unlist(colnames[i]), data = VBPersonasMulti)
plot(anal)
}
but when the code tries to use the member of the list as a key in its lm function i get this error:
Error in model.frame.default(formula = open ~ unlist(colname[i]), data = VBPersonasMulti, : variable lengths differ (found for 'unlist(colname[i])')
if i try to access the column name using colname[i] or colname[[i]] i get the error:
invalid type (list) for variable 'colname[i]'
Sorry for the newbie question and if i've struggled to describe the problem accurately.
What I would like to happen is that for each column name the lm function will run using the column name as the second argument to lm