[R] if else statement
Richard O'Keefe
r@oknz @end|ng |rom gm@||@com
Tue May 5 02:41:53 CEST 2020
Your ifelse expression looks fine. What goes wrong with it?
On Tue, 5 May 2020 at 05:16, 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 NA 2
> 6: fam1052 G1052 1 1
> ...
> > unique(b$PLASER)
> [1] 1 2 NA
> > unique(b$FLASER)
> [1] 1 2 NA
>
> how can I do if else statement so that I am creating a
> PHENO =2 if b$FLASER=2 or b$PLASER=2
> PHENO=1 if b$FLASER=1 and b$PLASER=1
> otherwise PHENO=NA
>
> I tried this but I am not sure if this is correct:
> b$pheno=ifelse(b$PLASER==1 & b$FLASER==1,1,ifelse(b$PLASER==2 |
> b$FLASER==2,2,NA))
>
> Thanks
> Ana
>
> [[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