[R] bind tables

arun smartpink111 at yahoo.com
Sat Jan 12 19:52:43 CET 2013


Hi,

You don't even need to split.
This could be done
dat1<-read.table(text="
year  h  len fre
1994  5 10.5  2
1994  5 14.0  2
1994  5 11.5  1
1994  9 13.0  3
1994  9 11.5  1
1994  9 13.5  5
",sep="",header=TRUE)

 dat1[rep(row.names(dat1),dat1$fre),1:3]
#    year h  len
#1   1994 5 10.5
#1.1 1994 5 10.5
#2   1994 5 14.0
#2.1 1994 5 14.0
#3   1994 5 11.5
#4   1994 9 13.0
#4.1 1994 9 13.0
#4.2 1994 9 13.0
#5   1994 9 11.5
#6   1994 9 13.5
#6.1 1994 9 13.5
#6.2 1994 9 13.5
#6.3 1994 9 13.5
#6.4 1994 9 13.5
A.K.



----- Original Message -----
From: "mmurenu at tiscali.it" <mmurenu at tiscali.it>
To: smartpink111 at yahoo.com
Cc: 
Sent: Saturday, January 12, 2013 1:23 PM
Subject: bind tables

Hi Arun,
Thank you very much for your reply.
I know that I was not clear enough, since my basic knowledge of r language.
To be more clear....

I have this df:

year  h  len fre
1994  5 10.5   2
1994  5 14.0   2
1994  5 11.5   1
1994  9 13.0   3
1994  9 11.5   1
1994  9 13.5   5


MY goal is to obtain:

year  h  len
1994  5 10.5
1994  5 10.5
1994  5 14.0
1994  5 14.0
1994  5 11.5
1994  9 13.0
1994  9 13.0
1994  9 13.0
1994  9 11.5
1994  9 13.5
1994  9 13.5
1994  9 13.5

i.e. disaggregate the freq variable.

To do that I'm trying to rbind as follow:
each row with fre=2 twice (aa,aa) having subset aa for fre=2
each row with fre=3 three times (aa,aa,aa) having subset aa for fre=3
each row with fre=3 three times (aa,aa,aa,aa,aa) having subset aa for fre=5

You probably know a faster and less rude way :)
best
Matteo




More information about the R-help mailing list