[R] Changing selected columns to factor

Jeff Reichman re|chm@nj @end|ng |rom @bcg|ob@|@net
Wed Jun 13 04:19:06 CEST 2018


Well that’s easy enough - thank you

-----Original Message-----
From: Jim Lemon <drjimlemon using gmail.com> 
Sent: Monday, June 11, 2018 11:50 PM
To: Jeff Reichman <reichmanj using sbcglobal.net>
Cc: r-help mailing list <r-help using r-project.org>
Subject: Re: [R] Changing selected columns to factor

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