[R] expand only one of variable

Muhammad Subianto msubianto at gmail.com
Thu Jun 8 11:13:24 CEST 2006


Dear all,
I want to expand only one of variable in data frame and the others
variable will be following with the expand variable. Here my toy example:

toy.df <- data.frame(size=c(3,1,2,0,3,5,1,0), group=LETTERS[1:8],

country=c("Germany","England","Argentina","Mexico","Italy","Brazil","France","Spain"),
                     w=rep(0,8), d=rep(0,8), l=rep(0,8))
toy.df

The size variable is the number of expand and signed by positive but size
with 0 (zero) must be signed by negative.
The result something like:

  size group   country w d l      sign
     3     A   Germany 0 0 0  positive
     3     A   Germany 0 0 0  positive
     3     A   Germany 0 0 0  positive
     1     B   England 0 0 0  positive
     2     C Argentina 0 0 0  positive
     2     C Argentina 0 0 0  positive
     0     D    Mexico 0 0 0  negative
     3     E     Italy 0 0 0  positive
     3     E     Italy 0 0 0  positive
     3     E     Italy 0 0 0  positive
     5     F    Brazil 0 0 0  positive
     5     F    Brazil 0 0 0  positive
     5     F    Brazil 0 0 0  positive
     5     F    Brazil 0 0 0  positive
     5     F    Brazil 0 0 0  positive
     1     G    France 0 0 0  positive
     0     H     Spain 0 0 0  negative

I  would be very happy if anyone could help me.
Thank you very much in advance.

Kindly regards, Muhammad Subianto



More information about the R-help mailing list