[R] Replacement Value

arun smartpink111 at yahoo.com
Wed Apr 9 09:10:29 CEST 2014


Hi Dila,

If 'dat' is the dataset:
dat$C[dat$B==0] <- 0 

A.K.
On Wednesday, April 9, 2014 1:30 AM, dila radi <dilaradi21 at gmail.com> wrote:

Dear arun
Yes indeed..if the value in B is O..next value in the same row also 0..
other value than 0 remains unchanged.
On Apr 9, 2014 12:48 PM, "arun" <smartpink111 at yahoo.com> wrote:

Dear Dila,
>
>What I understand from your two rules are that there is only one rule and that is concerning with '0' for B.  All other values are left without any change.
>
>
>
>
>
>On Wednesday, April 9, 2014 12:45 AM, dila radi <dilaradi21 at gmail.com> wrote:
>
>Dear Arun
>I just concern on values 1 and 0 only. Other values did not follow the rules I mention before. Thank you.
>Dila
>On Apr 8, 2014 5:28 PM, "arun" <smartpink111 at yahoo.com> wrote:
>
>HI,
>>What about values >1.0 for B?  Does it also follow the same rule as your second rule.
>>A.K.
>>
>>
>>
>>
>>
>>On Tuesday, April 8, 2014 12:11 AM, dila radi <dilaradi21 at gmail.com> wrote:
>>Hi all,
>>
>>I have problem on how to replace value. I have this kind of data set:
>>
>>structure(list(A = c(0, 12.6, 10.1, 8.1, 14.4, 0, 0, 0, 0, 0.5,
>>12.9, 25.9, 49, 0, 0, 0, 0, 0, 7.8), B = c(0, 0, 9.1, 9.3, 1.5,
>>1, 1, 1, 1.7, 6, 0, 0, 0, 1.7, 3.8, 0, 0, 0, 1), C = c(1, 1,
>>9.100000004, 9.299999999, 1.5, 1, 1, 1, 1.7, 5.999999999, 1,
>>1, 1, 1.7, 3.800000001, 1, 1, 1, 1)), .Names = c("A", "B", "C"
>>), row.names = c(NA, 19L), class = "data.frame")
>>
>>The problem is the value under variable 'C'.   It supposed to be like this:
>>
>>1) When value is '0' under variable 'B', the next value under variable 'C'
>>also should be '0'.
>>
>>2) When value is '1' under variable 'B', there is no changes for values
>>under variable 'C'.
>>
>>How do I achieved this by fulfill these two conditions? Thank you so much.
>>
>>
>>Regards,
>>Dila
>>
>>    [[alternative HTML version deleted]]
>>
>>______________________________________________
>>R-help at 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.
>>
>>
>




More information about the R-help mailing list