Re: [R] how to create a new column from two columns with conditions

2020-04-29 Thread Rui Barradas
Hello, Inline. Às 22:44 de 29/04/20, Ana Marija escreveu: Hi Rui, thanks for getting back to me so I tried your method and I got: sum(b$PHENO==2, na.rm=T) [1] 828 sum(b$PHENO==1, na.rm=T) [1] 859 Can you please tell me if b$PHENO <- (b$FLASER == 2 | b$PLASER == 2) + 1L just assigns PHENO

Re: [R] how to create a new column from two columns with conditions

2020-04-29 Thread Ana Marija
Thank you so much, numbers add up now! On Wed, Apr 29, 2020 at 5:09 PM wrote: > > While I've sent you a maths way to do it, > > I'd probably take this approach; > > # set b$pheno to 1 as default > > b$pheno <- 1 > > # set the flaser > > b$pheno[b$flaser == 2] <- 2 > > #set the plaser > > b$pheno[

Re: [R] how to create a new column from two columns with conditions

2020-04-29 Thread Ana Marija
Hi Rui, thanks for getting back to me so I tried your method and I got: > sum(b$PHENO==2, na.rm=T) [1] 828 > sum(b$PHENO==1, na.rm=T) [1] 859 Can you please tell me if b$PHENO <- (b$FLASER == 2 | b$PLASER == 2) + 1L just assigns PHENO=2 if b$FLASER == 2 | b$PLASER == 2 and everything else is 1?

Re: [R] how to create a new column from two columns with conditions

2020-04-29 Thread Ege Rubak
Or if you prefer not to load an entire suite of packages to do such a simple task you could use b$PHENO <- ifelse(...) or in this specific case it seems sufficient to do b$PHENO <- pmax(b$FLASER, b$PLASER) /Ege On Wed, 2020-04-29 at 15:30 -0400, Patrick (Malone Quantitative) wrote: > If you do

Re: [R] how to create a new column from two columns with conditions

2020-04-29 Thread Rui Barradas
Hello, Here is another way. The condition returns FALSE/TRUE or 0/1. Add 1 to get the expected result. It has the advantage of being faster. b$PHENO <- (b$FLASER == 2 | b$PLASER == 2) + 1L Hope this helps, Rui Barradas Às 20:42 de 29/04/20, Ana Marija escreveu: Thanks, I did this: b$PHENO

Re: [R] how to create a new column from two columns with conditions

2020-04-29 Thread Ana Marija
Thanks, I did this: b$PHENO<- ifelse(b$FLASER ==2 | b$PLASER ==2, 2, 1) On Wed, Apr 29, 2020 at 2:36 PM Ivan Krylov wrote: > > On Wed, 29 Apr 2020 14:19:18 -0500 > Ana Marija wrote: > > > My conditions for creating a new column PHENO would be this: > > > > if FLASER or PLASER =2 then PHENO=2 > >

Re: [R] how to create a new column from two columns with conditions

2020-04-29 Thread Ivan Krylov
On Wed, 29 Apr 2020 14:19:18 -0500 Ana Marija wrote: > My conditions for creating a new column PHENO would be this: > > if FLASER or PLASER =2 then PHENO=2 > otherwise PHENO=1 On Wed, 29 Apr 2020 15:30:45 -0400 "Patrick (Malone Quantitative)" wrote: > If you don't mind using tidyverse, you ca

Re: [R] how to create a new column from two columns with conditions

2020-04-29 Thread Patrick (Malone Quantitative)
If you don't mind using tidyverse, you can do this easily with if_else. b$PHENO<-if_else(... On Wed, Apr 29, 2020 at 3:21 PM Ana Marija wrote: > Hello, > > I have a data frame like this: > > > head(b) >FID IID FLASER PLASER > 1: fam1000 G1000 1 1 > 2: fam1001 G1001

[R] how to create a new column from two columns with conditions

2020-04-29 Thread Ana Marija
Hello, I have a data frame like this: > head(b) FID IID FLASER PLASER 1: fam1000 G1000 1 1 2: fam1001 G1001 1 1 3: fam1003 G1003 1 2 4: fam1005 G1005 1 1 5: fam1009 G1009 2 1 6: fam1052 G1052 1 1 ... My conditions for cr