[R] data frame manipulation with conditions

A2CT2 Trading trading at a2ct2.com
Fri Feb 24 16:11:30 CET 2012

Dear list,

n00b question, but still can't find any easy answer.

Here is a df:

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

I want to modify this df this way :
 if df$x=="AA" then df$y=df$y*10
 if df$x=="BB" then df$y=df$y*25

and so on with other conditions.

TY for any help.

A2CT2 Ltd.

More information about the R-help mailing list