I created the following function to convert every character column of a data frame (x) into a factor one, but I got an error message as "Error in if (e[i]) { : argument is not interpretable as logical." Any help would be appreciated.
f<-function(x){
e<-lapply(x, is.character)
i <- 1
while (i >= 1) {
if(e[i]) {as.factor(x[[i]])}
else {x[i]}
}
x
}