[R] data frame subscription

David Winsemius dwinsemius at comcast.net
Wed May 12 17:07:18 CEST 2010


Couldn't you just put a minus sign in from of the derived "prix"  
expression?

transform(pose16, prix = - POSITION * SETTLEMENT, SETTLEMENT = NULL,  
POSITION
= POSITION * -1)

On May 12, 2010, at 10:59 AM, Henrique Dallazuanna wrote:

> But:
>
> pose16$POSITION * pose16$SETTLEMENT is
> [1]  -702.90   244.77   166.48  2273.80 24876.00  2985.00    80.90
> -15.95  2512.50 -2423.00
>
> not:
> c(702.9,  -244.77, -166.48, -2273.8, -24876, -2985, -80.9, 15.95,  
> -2512.5,
> 2423)
>
>
> On Wed, May 12, 2010 at 11:53 AM, arnaud Gaboury
> <arnaud.gaboury at gmail.com>wrote:
>
>> The result is different with your code.
>>
>> My result is :
>>
>> pose16 <-
>> structure(list(DESCRIPTION = structure(c(1L, 2L, 3L, 4L, 5L,
>> 6L, 7L, 8L, 9L, 12L), .Label = c("COPPER May/10", "COTTON NO.2 Jul/ 
>> 10",
>> "CRUDE OIL miNY May/10", "GOLD Jun/10", "ROBUSTA COFFEE (10) Jul/10",
>> "SOYBEANS Jul/10", "SUGAR NO.11 Jul/10", "SUGAR NO.11 May/10",
>> "WHEAT Jul/10", "PRIMARY NICKEL USD", "PRM HGH GD ALUMINIUM USD",
>> "SPCL HIGH GRADE ZINC USD", "STANDARD LEAD USD"), class = "factor"),
>>    POSITION = c(2, -3, -2, -2, -18, -3, -5, 1, -5, 1), prix =  
>> c(702.9,
>>   -244.77, -166.48, -2273.8, -24876, -2985, -80.9, 15.95, -2512.5,
>>   2423)), .Names = c("DESCRIPTION", "POSITION", "prix"), row.names =
>> c("1",
>> "2", "3", "4", "5", "6", "7", "8", "9", "51"), class = "data.frame")
>>
>> Your result is :
>>
>> pose16 <-
>> structure(list(DESCRIPTION = structure(c(1L, 2L, 3L, 4L, 5L,
>> 6L, 7L, 8L, 9L, 12L), .Label = c("COPPER May/10", "COTTON NO.2 Jul/ 
>> 10",
>> "CRUDE OIL miNY May/10", "GOLD Jun/10", "ROBUSTA COFFEE (10) Jul/10",
>> "SOYBEANS Jul/10", "SUGAR NO.11 Jul/10", "SUGAR NO.11 May/10",
>> "WHEAT Jul/10", "PRIMARY NICKEL USD", "PRM HGH GD ALUMINIUM USD",
>> "SPCL HIGH GRADE ZINC USD", "STANDARD LEAD USD"), class = "factor"),
>>    POSITION = c(2, -3, -2, -2, -18, -3, -5, 1, -5, 1), prix =  
>> c(-702.9,
>>   244.77, 166.48, 2273.8, 24876, 2985, 80.9, -15.95, 2512.5,
>>   -2423)), .Names = c("DESCRIPTION", "POSITION", "prix"), row.names =
>> c("1",
>> "2", "3", "4", "5", "6", "7", "8", "9", "51"), class = "data.frame")
>>
>>
>>
>>
>> From: Henrique Dallazuanna [mailto:wwwhsd at gmail.com]
>> Sent: Wednesday, May 12, 2010 3:32 PM
>> To: arnaud Gaboury
>> Cc: r-help at r-project.org
>> Subject: Re: [R] data frame subscription
>>
>> Try this:
>>
>> transform(pose16, prix = POSITION * SETTLEMENT, SETTLEMENT = NULL,  
>> POSITION
>> = POSITION * -1)
>>
>> On Wed, May 12, 2010 at 9:50 AM, arnaud Gaboury <arnaud.gaboury at gmail.com 
>> >
>> wrote:
>> Dear group,
>>
>> Here is my df :
>>
>> pose16 <-
>> structure(list(DESCRIPTION = structure(c(1L, 2L, 3L, 4L, 5L,
>> 6L, 7L, 8L, 9L, 12L), .Label = c("COPPER May/10", "COTTON NO.2 Jul/ 
>> 10",
>> "CRUDE OIL miNY May/10", "GOLD Jun/10", "ROBUSTA COFFEE (10) Jul/10",
>> "SOYBEANS Jul/10", "SUGAR NO.11 Jul/10", "SUGAR NO.11 May/10",
>> "WHEAT Jul/10", "PRIMARY NICKEL USD", "PRM HGH GD ALUMINIUM USD",
>> "SPCL HIGH GRADE ZINC USD", "STANDARD LEAD USD"), class = "factor"),
>>   POSITION = c(-2, 3, 2, 2, 18, 3, 5, -1, 5, -1), SETTLEMENT =  
>> c(351.45,
>>   81.59, 83.24, 1136.9, 1382, 995, 16.18, 15.95, 502.5, 2423
>>   )), .Names = c("DESCRIPTION", "POSITION", "SETTLEMENT"),  
>> row.names =
>> c("1",
>> "2", "3", "4", "5", "6", "7", "8", "9", "51"), class = "data.frame")
>>
>> Here is my code :
>>
>>> pose16$prix<-pose16[,2]*pose16[,3]
>>> pose16<-pose16[,-3]
>>> pose16[,-1]<- -pose16[,-1]
>>
>> It works fine, as the resulting df is what I want. I am just  
>> wandering if
>> these 3 command lines can be writen in only 1 or 2 lines??
>>
>> TY for the help.
>>
>> ______________________________________________
>> 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.
>>
>>
>>
>> --
>> Henrique Dallazuanna
>> Curitiba-Paraná-Brasil
>> 25° 25' 40" S 49° 16' 22" O
>>
>>
>
>
> -- 
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list