Say I have the following df
x<-c(1,3,2,4,1,3,2,4,1,3,2,4)
y<-c(rnorm(12))
df<-data.frame(x,y)
x is integer and I try to convert it to a factor using the suggestion from the R cookbook:
df[,'x']<-factor(df[,'x'])
But it still remains an integer. I have tried a solution found on the forum
df[,'x']<-lapply(df[,'x'], factor)
but it did not work either. Thanks.