[R] data frame manipulation with condition
Sarah Goslee
sarah.goslee at gmail.com
Fri Feb 24 17:19:39 CET 2012
I sent it to you and the list, as is standard practice.
You must know in advance what level of your factor goes with what multiplicand.
Use that information to set up the association. The order within your data frame
is irrelevant, only the order R uses for factor levels is of importance.
Sarah
On Fri, Feb 24, 2012 at 11:16 AM, Arnaud Gaboury
<arnaud.gaboury at a2ct2.com> wrote:
> No sorry! Your email was in fact NOT in the lsit, and was not watching my regular box, but only the list one.
>
> TY for your tip. But in fact my df is much more complex, and objects, numbers of it and their order will change
>
> Have a good weekend
>
> Arnaud Gaboury
>
> A2CT2 Ltd.
> Trade: +41 22 849 88 63
> Fax: +41 22 849 88 66
> arnaud.gaboury at a2ct2.com
>
> -----Original Message-----
> From: Sarah Goslee [mailto:sarah.goslee at gmail.com]
> Sent: vendredi 24 février 2012 17:12
> To: Arnaud Gaboury
> Subject: Re: [R] data frame manipulation with condition
>
> Did you not see my solution?
>
> On Fri, Feb 24, 2012 at 10:59 AM, Arnaud Gaboury <arnaud.gaboury at a2ct2.com> 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 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:
>>> 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.
>>>
--
Sarah Goslee
http://www.functionaldiversity.org
More information about the R-help
mailing list