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
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
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
-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
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
-
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
]
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
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
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
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
-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
-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
.
-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
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 *
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
15 matches
Mail list logo