On Apr 10, 2012, at 3:16 AM, aajit75 wrote:

I have got solution using within function as below

dd$Seg <- 1
dd <- within(dd, Seg[x2> 0 & x3> 200] <- 1)

In this instance the first of your assignments appears superfluous.

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!!



dd <- with(dd, Seg <- min(findInterval(x2, c(-Inf ,100, 200, 300, Inf) ), findInterval(x3, C(-Inf ,300, 400, 500, Inf) )
           )               )


David Winsemius, MD
West Hartford, CT

______________________________________________
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.

Reply via email to