[R] data frame manipulation with condition
    Uwe Ligges 
    ligges at statistik.tu-dortmund.de
       
    Fri Feb 24 16:33:04 CET 2012
    
    
  
On 24.02.2012 16:25, Arnaud Gaboury wrote:
> Dear list,
>
> n00b question, but still can't find any easy answer.
>
> Here is a df:
Change
>> df<-data.frame(cbind(x=c("AA","BB","CC","AA"),y=1:4))
to
  df <- data.frame(x = c("AA","BB","CC","AA"), y = 1:4)
to make your object a sensible data.frame.
>> 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
df$y[df$x=="AA"] <- df$y[df$x=="AA"] * 25
...
Uwe Ligges
>   if df$x=="BB" then df$y=df$y*25
> and so on with other conditions.
>
> TY for any help.
>
> Trading
>
> A2CT2 Ltd.
>
>
> Arnaud Gaboury
>
> A2CT2 Ltd.
>
> ______________________________________________
> 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