On 2020-06-13 19:09 +1000, Jim Lemon wrote:
> Right, back from shopping. Since you have fourteen rows containing NAs
> and you only want seven, we can infer that half of them must go. As
> they are neatly divided into seven rows in which only one NA appears
> and seven in which two stare meaninglessly out at us. I will assume
> that the latter are the ones to be discarded. As your condition for
> calculating "pheno" stated that a 2 in either FLASER or PLASER should
> result in a 2 in pheno, the following statement closely conforms to
> that:
> 
> b<-read.table(text="FID   IID FLASER PLASER
>   fam1837 G1837      1     NA
>   fam2410 G2410     NA     NA
>   fam2838 G2838     NA      2
>   fam3367 G3367      1     NA
>   fam3410 G3410      1     NA
>   fam3492 G3492      1     NA
>   fam0911  G911     NA     NA
>   fam3834 G3834      2     NA
>   fam4708 G4708     NA      2
>   fam5162 G5162     NA     NA
>   fam5274 G5274     NA     NA
>   fam0637  G637     NA     NA
>   fam0640  G640     NA     NA
>   fam0743  G743     NA     NA
>   fam0911  G911     NA     NA",
>   header=TRUE,stringsAsFactors=FALSE)
> 
> b$pheno<-ifelse(b$FLASER == 2 | b$PLASER == 2,2,1)
> # use the valid FLASER values when PLASER is NA
> b[is.na(b$pheno),]$pheno<-ifelse(!is.na(b[is.na(b$pheno),]$FLASER),
>  b[is.na(b$pheno),]$FLASER,NA)
> # use the valid PLASER values when FLASER if NA
> b[is.na(b$pheno),]$pheno<-ifelse(!is.na(b[is.na(b$pheno),]$PLASER),
>  b[is.na(b$pheno),]$PLASER,NA)
> b
> 
> I could write that mess in one straitjacket of conditional statements
> but my brain hurts enough.

I think this answer is billiant!

Here's a picture of my laptop screen out in my local park 
yesterday as I was trying to figure this out

https://mega.nz/#!OERQFSgL!McUkMYwkrcQXN148Wr11K1xRHSTOWVFfz4gRwaZYLzM

I have nothing more to add at the moment :)

/Rasmus

Attachment: signature.asc
Description: PGP signature

______________________________________________
R-help@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.

Reply via email to