Re: [R] Help with if else statement

2019-08-08 Thread Linus Chen
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

Re: [R] Help with if else statement

2019-08-07 Thread Jim Lemon
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

Re: [R] Help with if else statement

2019-08-07 Thread Bert Gunter
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

Re: [R] Help with if else statement

2019-08-07 Thread Andrew Robinson
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

Re: [R] Help with if else statement

2019-08-07 Thread Ana Marija
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