[R] Changing selected columns to factor

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Tue Jun 12 06:49:30 CEST 2018


Hi Jeff,

jrdf<-data.frame(A=rnorm(10),B=rnorm(10),C=rnorm(10),
 D=rnorm(10),E=rnorm(10),F=rnorm(10),G=rnorm(10),
 H=rnorm(10),I=rnorm(10),J=rnorm(10))
for(i in c(2,7,8,9)) jrdf[,i]<-factor(jrdf[,i])
sapply(jrdf,"class")

Jim

On Tue, Jun 12, 2018 at 9:57 AM, Jeff Reichman <reichmanj using sbcglobal.net> wrote:
> R-Help Forum
>
>
>
> If I have a data frame consisting of say ten (10) variables
> (A,B,C,D,E,F,G,H,I,J) and I want to change Variables 2,7,8,and 9 to factors
> is there a command such that I can do it in one line or do I simply have to
> convert each separately?
>
>
>
> Jeff
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list