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
y of Melbourne, VIC 3010 Australia Email: a...@unimelb.edu.au Website: http://cebra.unimelb.edu.au/ From: R-help on behalf of Ana Marija Sent: Thursday, August 8, 2019 4:37 am To: r-help Subject: [R] Help with if else statement Hello, I have a data frame which l

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

[R] Help with if else statement

2019-08-07 Thread Ana Marija
Hello, I have a data frame which looks like this: > head(pt) eidQ phenoQ phenoH 1 117 -9 -9 2 125 -9 -9 3 138 -9 1 4 142 -9 -9 5 156 -9 -9 6 174 -9 -9 7 138 -9 1 8 1000127 2 1 9 1000690 2