[R] how to create a new column from two columns with conditions
Patrick (Malone Quantitative)
m@|one @end|ng |rom m@|onequ@nt|t@t|ve@com
Wed Apr 29 21:30:45 CEST 2020
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 <sokovic.anamarija using gmail.com>
wrote:
> 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 creating a new column PHENO would be this:
>
> if FLASER or PLASER =2 then PHENO=2
> otherwise PHENO=1
>
> so result would look like this:
>
> > head(b)
> FID IID FLASER PLASER PHENO
> 1: fam1000 G1000 1 1 1
> 2: fam1001 G1001 1 1 1
> 3: fam1003 G1003 1 2 2
> 4: fam1005 G1005 1 1 1
> 5: fam1009 G1009 2 1 2
> 6: fam1052 G1052 1 1 1
> ...
>
> Thanks
> Ana
> ...
>
> ______________________________________________
> 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.
>
--
Patrick S. Malone, Ph.D., Malone Quantitative
NEW Service Models: http://malonequantitative.com
He/Him/His
[[alternative HTML version deleted]]
More information about the R-help
mailing list