Bert's answer is great, but since there is only two columns to be
used, why not simply
pt$pheno <- pmax( p$phenoQ ,p$phenoH )
Cheers,
Lei
On Wed, 7 Aug 2019 at 21:23, Bert Gunter wrote:
>
> The ifelse() construction is fast, but after a couple of nested iterations,
> it gets messy and error-pron
Hi Ana,
Or just for a bit of fun:
pt<-read.table(text="eidQ phenoQ phenoH
117 -9 -9
125 -9 -9
138 -9 1
142 -9 -9
156 -9 -9
174 -9 -9
138 -9 1
1000127 2 1
1000690 2 -9
1000711 2
The ifelse() construction is fast, but after a couple of nested iterations,
it gets messy and error-prone; so I believe to be avoided.
In your case, there is a much better alternative, ?pmax . Ergo, something
like:
pt$pheno <- do.call(pmax, pt[, -1])
?do.call is necessary to pass the list of col
pmax() should work in this instance, as in any case you want the larger value.
Andrew
--
Andrew Robinson
Director, CEBRA, School of BioSciences
Reader & Associate Professor in Applied Statistics Tel: (+61) 0403 138 955
School of Mathematics and Statistics Fax: (+61) 03 8344 4599
University of Mel
does this look ok:
pt$pheno=ifelse(pt$phenoQ==-9 & pt$phenoH==-9,-9,ifelse(pt$phenoH==2 |
pt$phenoQ==2,2,1))
On Wed, Aug 7, 2019 at 1:40 PM Ana Marija wrote:
>
> Hello,
>
> I have a data frame which looks like this:
>
> > head(pt)
> eidQ phenoQ phenoH
> 1 117 -9 -9
> 2 125
5 matches
Mail list logo