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. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.