Skip to content
Prev 286325 / 398502 Next

data frame manipulation with condition

TY Uwe,

So I will have to write a line for each condition? Right?

In fact I was trying to do something with apply in one line, but couldn't achieve any result. In fact, all my transformation will be multiplying one object by a specific number according to the value of df$x.

Arnaud Gaboury
?
A2CT2 Ltd.


-----Original Message-----
From: Uwe Ligges [mailto:ligges at statistik.tu-dortmund.de] 
Sent: vendredi 24 f?vrier 2012 16:33
To: Arnaud Gaboury
Cc: r-help at r-project.org
Subject: Re: [R] data frame manipulation with condition
On 24.02.2012 16:25, Arnaud Gaboury wrote:
Change
to

  df <- data.frame(x = c("AA","BB","CC","AA"), y = 1:4)

to make your object a sensible data.frame.
df$y[df$x=="AA"] <- df$y[df$x=="AA"] * 25

...


Uwe Ligges