Re: [R] create multiple categorical variables in a data frame using a loop

2018-04-20 Thread Ding, Yuan Chun
] create multiple categorical variables in a data frame using a loop [Attention: This email came from an external source. Do not open attachments or click on links from unknown senders or unexpected emails.] > On Apr 19, 2018, at 1:22 PM, David Winsemius wrote: > > >> On Apr

Re: [R] create multiple categorical variables in a data frame using a loop

2018-04-19 Thread David Winsemius
> On Apr 19, 2018, at 1:22 PM, David Winsemius wrote: > > >> On Apr 19, 2018, at 11:20 AM, Ding, Yuan Chun wrote: >> >> Hi All, >> >> I want to create a categorical variable, cat.pfoa, in the file of pfas.pheno >> (a data frame) based on log2pfoa values. I can do it using the following >>

Re: [R] create multiple categorical variables in a data frame using a loop

2018-04-19 Thread David Winsemius
> On Apr 19, 2018, at 11:20 AM, Ding, Yuan Chun wrote: > > Hi All, > > I want to create a categorical variable, cat.pfoa, in the file of pfas.pheno > (a data frame) based on log2pfoa values. I can do it using the following code. > > pfas.pheno <-within(pfas.pheno, {cat.pfoa<-NA > cat.pfoa[pf

Re: [R] create multiple categorical variables in a data frame using a loop

2018-04-19 Thread Ding, Yuan Chun
variables in a data frame using a loop [Attention: This email came from an external source. Do not open attachments or click on links from unknown senders or unexpected emails.] Hello, When programming it is better to use dat[["variable"]] than dat$variable. So your code could be

Re: [R] create multiple categorical variables in a data frame using a loop

2018-04-19 Thread Rui Barradas
Hello, When programming it is better to use dat[["variable"]] than dat$variable. So your code could be pfas.pheno[[cat.var]] <- NA pfas.pheno[[cat.var]][pfas.pheno[,i] <= quantile(pfas.pheno[,i],0.25, na.rm =T)] <- 0 etc. Untested. Hope this helps, Rui Barradas On 4/19/2018 7:20 PM, Ding

[R] create multiple categorical variables in a data frame using a loop

2018-04-19 Thread Ding, Yuan Chun
Hi All, I want to create a categorical variable, cat.pfoa, in the file of pfas.pheno (a data frame) based on log2pfoa values. I can do it using the following code. pfas.pheno <-within(pfas.pheno, {cat.pfoa<-NA cat.pfoa[pfas.pheno$log2pfoa <=quantile(pfas.pheno$log2pfoa,0.25, na.rm =T)]<-0 c