I have a data frame(s) df1,df2,... that I am accessing through a for loop (R for loop I know...) I need to assign the last column (y variable) to be a factor. I am attempting to do it like this:
get(paste0('df',x))[,ncol(get(paste0('df',x)))] <- as.factor(get(paste0('df',x))[,ncol(get(paste0('df',x)))])
however I am getting the 'target of assignment expands to non-language object' error when I try to do this.
Why is this not behaving the same way as this?
df1[,19] <- as.factor(df1[,19])
and is there a way to assign my columns as factors given that it must be done through a process similar to this?