elp [mailto:r-help-boun...@r-project.org] On Behalf Of Kuma
> Raj
> Sent: Monday, March 23, 2015 1:59 PM
> To: r-help@r-project.org
> Subject: [R] Replace a column value on condition
>
> I want to replace column c3 with values from column c2 whenever values
> of column Id are 2.
> On 23-03-2015, at 13:58, Kuma Raj wrote:
>
> I want to replace column c3 with values from column c2 whenever values
> of column Id are 2. In stata I could use replace c3 = c2 if id ==2.
> How could I do that in R?
>
k <- which(df4$id==2)
df4[k,"c3"] <- df4[k,"c2”]
Berend
> Thanks
>
>
>
I want to replace column c3 with values from column c2 whenever values
of column Id are 2. In stata I could use replace c3 = c2 if id ==2.
How could I do that in R?
Thanks
Sample data found below:
> dput(df4)
structure(list(c2 = c(42L, 42L, 47L, 47L, 55L, 55L, 36L, 36L,
61L, 61L), c3 = c(68L, 5
3 matches
Mail list logo