[R] data frame manipulation with condition

2012-02-24 Thread Arnaud Gaboury
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

Re: [R] data frame manipulation with condition

2012-02-24 Thread Uwe Ligges
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

Re: [R] data frame manipulation with condition

2012-02-24 Thread Arnaud Gaboury
  A2CT2 Ltd. -Original Message- From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] Sent: vendredi 24 février 2012 16:33 To: Arnaud Gaboury Cc: r-help@r-project.org Subject: Re: [R] data frame manipulation with condition On 24.02.2012 16:25, Arnaud Gaboury wrote: Dear list, n00b

Re: [R] data frame manipulation with condition

2012-02-24 Thread Uwe Ligges
-help@r-project.org Subject: Re: [R] data frame manipulation with condition 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

Re: [R] data frame manipulation with condition

2012-02-24 Thread Sarah Goslee
To: Arnaud Gaboury Cc: r-help@r-project.org Subject: Re: [R] data frame manipulation with condition 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

Re: [R] data frame manipulation with condition

2012-02-24 Thread Arnaud Gaboury
- From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] Sent: vendredi 24 février 2012 17:07 To: Arnaud Gaboury Cc: r-help@r-project.org Subject: Re: [R] data frame manipulation with condition On 24.02.2012 16:59, Arnaud Gaboury wrote: TY Uwe, So I will have to write a line for each

Re: [R] data frame manipulation with condition

2012-02-24 Thread Uwe Ligges
] Sent: vendredi 24 février 2012 17:07 To: Arnaud Gaboury Cc: r-help@r-project.org Subject: Re: [R] data frame manipulation with condition On 24.02.2012 16:59, Arnaud Gaboury wrote: TY Uwe, So I will have to write a line for each condition? Right? In fact I was trying to do something with apply

Re: [R] data frame manipulation with condition

2012-02-24 Thread Sarah Goslee
Ltd. -Original Message- From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] Sent: vendredi 24 février 2012 17:07 To: Arnaud Gaboury Cc: r-help@r-project.org Subject: Re: [R] data frame manipulation with condition On 24.02.2012 16:59, Arnaud Gaboury wrote: TY Uwe, So I

Re: [R] data frame manipulation with condition

2012-02-24 Thread Arnaud Gaboury
2012 17:41 To: Arnaud Gaboury Cc: r-help@r-project.org Subject: Re: [R] data frame manipulation with condition On 24.02.2012 17:36, Arnaud Gaboury wrote: df- data.frame(x = c(AA,BB,CC,AA,DD,DD), y = 1:6) mult- c(AA = 10, BB = 25,DD=15) df$y- df$y * mult[df$x] df x y 1 AA 10 2 BB 50 3

Re: [R] data frame manipulation with condition

2012-02-24 Thread Arnaud Gaboury
To: Arnaud Gaboury Cc: r-help@r-project.org Subject: Re: [R] data frame manipulation with condition You need, as I already suggested, to use a value of 1 for levels you don't want to change. mult - c(AA = 10, BB = 25, CC=1, DD=15) mult[df$x] AA BB CC AA DD DD 10 25 1 10 15 15 df$y * mult[df$x

Re: [R] data frame manipulation with condition

2012-02-24 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Arnaud Gaboury Sent: Friday, February 24, 2012 8:37 AM To: Uwe Ligges Cc: r-help@r-project.org Subject: Re: [R] data frame manipulation with condition df- data.frame(x = c(AA,BB,CC,AA,DD

Re: [R] data frame manipulation with condition

2012-02-24 Thread Sarah Goslee
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Arnaud Gaboury Sent: Friday, February 24, 2012 8:37 AM To: Uwe Ligges Cc: r-help@r-project.org Subject: Re: [R] data frame manipulation with condition df- data.frame(x = c(AA

Re: [R] data frame manipulation with condition

2012-02-24 Thread Arnaud Gaboury
. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Arnaud Gaboury Sent: vendredi 24 février 2012 18:17 To: Sarah Goslee Cc: r-help@r-project.org Subject: Re: [R] data frame manipulation with condition TY very much Sarah: your tip is doing

Re: [R] data frame manipulation with condition

2012-02-24 Thread Sarah Goslee
Whatever makes you happy. df1 - + structure(list(x = structure(c(1L, 2L, 2L, 3L), .Label = c(AA, + BB, CC), class = factor), y = 1:4), .Names = c(x, y + ), row.names = c(NA, -4L), class = data.frame) mult - c(AA=2,BB=5,CC=1,DD=2) df1$y * mult[df1$x] AA BB BB CC 2 10 15 4 df1$y *

Re: [R] data frame manipulation with condition

2012-02-24 Thread William Dunlap
Goslee [mailto:sarah.gos...@gmail.com] Sent: Friday, February 24, 2012 9:39 AM To: William Dunlap Cc: Arnaud Gaboury; r-help@r-project.org Subject: Re: [R] data frame manipulation with condition On Fri, Feb 24, 2012 at 12:23 PM, William Dunlap wdun...@tibco.com wrote: Use mult[as.character