I have a data set in R and I want to turn the first three columns into a factor with a for loop. What I did is:
newvar=names(data)[1:3]
for(v in newvar){
data[,v] = as.factor(data[,v])
}
this works fine. Can anyone tell me why
for( v in newvar){
data$v=as.factor(data$v)
}
won´t work?