Re: [R] expand only one of variable

From: Jacques VESLOT <jacques.veslot_at_good.ibl.fr>
Date: Thu 08 Jun 2006 - 19:35:37 EST

 > toy.df$sign <- ifelse(toy.df$size == 0, "negative", "positive")  > toy.df[rep(1:nrow(toy.df), ifelse(toy.df$size==0, 1, toy.df$size)),]



Jacques VESLOT

CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex

Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31

http://www-good.ibl.fr


Muhammad Subianto a écrit :
> 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
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jun 08 19:39:57 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 08 Jun 2006 - 20:10:38 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.