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

2012-04-10 Thread David Winsemius
On Apr 10, 2012, at 8:59 AM, David Winsemius wrote: 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,

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

2012-04-10 Thread David Winsemius
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>

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

2012-04-10 Thread Berend Hasselman
On 10-04-2012, at 08:44, aajit75 wrote: > Hi Experts, > > This may be simple question, I want to create new variable "seg" and assign > values to it based on some conditions satisfied by each observation. > > Here is the example: > ##Below are the conditions > > ##if variable x2 gt 0 and x3 gt

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

2012-04-10 Thread aajit75
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 th

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

2012-04-10 Thread aajit75
Hi Experts, This may be simple question, I want to create new variable "seg" and assign values to it based on some conditions satisfied by each observation. Here is the example: ##Below are the conditions ##if variable x2 gt 0 and x3 gt 200 then seg should take value 1, ##if variable x2 gt 100