On 04/08/2014 01:46 PM, dila radi 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.
>
Hi Dila,
The answer to the above is fairly simple (data frame is named drdf):
drdf$C[which(drdf$B==0)+1]<-0
The second condition does nothing. However, I think that you may want
something more complicated as there are values other than 0 or 1 in drdf.
Jim