[R] Assign value to new variable based on conditions on other variables

aajit75 aajit75 at yahoo.co.in
Tue Apr 10 09:16:50 CEST 2012


I have got solution using within function as below

dd$Seg <- 1
dd <- within(dd, Seg[x2> 0 & x3> 200] <- 1) 
dd <- within(dd, Seg[x2> 100 & x3> 300] <- 2) 
dd <- within(dd, Seg[x2> 200 & x3> 400] <- 3) 
dd <- within(dd, Seg[x2> 300 & x3> 500] <- 4)

I sthere any better way of doing it!!

--
View this message in context: http://r.789695.n4.nabble.com/Assign-value-to-new-variable-based-on-conditions-on-other-variables-tp4544753p4544795.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list