Re: [R] Creating a new var from conditional values in other vars

2013-06-12 Thread arun
Hi `Bangali`, You can type in the R Console ?with()  ?ifelse() The details and some examples are there. In addition to ?with(), you can use: ?within dat1<-within(dat1,pattern<-ifelse(A>20 & B<=2.5 & C<=20,"Normal",ifelse(A <20 & B >2.5 & C >20,"Increased",ifelse(A >=20 & B >2.5 & C <=20,"Low","

Re: [R] Creating a new var from conditional values in other vars

2013-06-12 Thread arun
Hi, Try this: set.seed(25) dat1<- data.frame(A=sample(1:30,100,replace=TRUE),B=sample(1:35,100,replace=TRUE),C=sample(1:25,100,replace=TRUE)) dat1$pattern<-with(dat1,ifelse(A>20 & B<=2.5 & C<=20,"Normal",ifelse(A <20 & B >2.5 & C >20,"Increased",ifelse(A >=20 & B >2.5 & C <=20,"Low","Other"