An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-sig-epi/attachments/20071104/dac015af/attachment.pl
Data.Frame Desaggregation
3 messages · Márcio Ribeiro, Ross Darnell, BXC (Bendix Carstensen)
Ribeiro Why not (modified df1)
df1 <- data.frame(Y=c(3,1,1,2),m=c(3,4,3,2)) df1
Y m 1 3 3 2 1 4 3 1 3 4 2 2
df1[rep(row.names(df1),rep(3,dim(df1)[1])),]
Y m
1 3 3
1.1 3 3
1.2 3 3
2 1 4
2.1 1 4
2.2 1 4
3 1 3
3.1 1 3
3.2 1 3
4 2 2
4.1 2 2
4.2 2 2
Ross Darnell
-----Original Message-----
From: r-sig-epi-bounces at stat.math.ethz.ch [mailto:r-sig-epi-bounces at stat.math.ethz.ch] On Behalf Of M?rcio Ribeiro
Sent: Monday, 5 November 2007 3:29 AM
To: r-sig-epi at stat.math.ethz.ch
Subject: [R-sig-Epi] Data.Frame Desaggregation
Hi Listers,
I am trying to transform the data.frame above in a more detailed data.frame... I checked a example at the website, but I didn't understand at all.
data.frame(x = with(df1, rep(x, m)))
What does the df1 means...
My data looks like this...
Y m X1 X2
1 3 3 12.0 0.8
2 1 4 4.1 67.5
3 1 3 2.4 12.4
4 2 2 11.2 7.7
My object is to obtain this...
Y m X1 X2
1 1 . 12.0 0.8
1 1 . 12.0 0.8
1 1 . 12.0 0.8
2 1 . 4.1 67.5
2 0 . 4.1 67.5
2 0 . 4.1 67.5
2 0 . 4.1 67.5
3 1 . 2.4 12.4
3 0 . 2.4 12.4
3 0 . 2.4 12.4
4 1 . 11.2 7.7
4 1 . 11.2 7.7
Thanks in advance,
Ribeiro
---------------------------------
_______________________________________________
R-sig-Epi at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-epi
I think what was meant was the the rows of the dataframe should be repeated "m" times, i.e. rather:
df1[rep(row.names(df1),df1$m),]
Y m 1 3 3 1.1 3 3 1.2 3 3 2 1 4 2.1 1 4 2.2 1 4 2.3 1 4 3 1 3 3.1 1 3 3.2 1 3 4 2 2 4.1 2 2 Bets, Bendix Carstensen ______________________________________________ Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2-4 DK-2820 Gentofte Denmark +45 44 43 87 38 (direct) +45 30 75 87 38 (mobile) +45 44 43 73 13 (fax) bxc at steno.dk http://www.biostat.ku.dk/~bxc
-----Original Message----- From: r-sig-epi-bounces at stat.math.ethz.ch [mailto:r-sig-epi-bounces at stat.math.ethz.ch] On Behalf Of Ross Darnell Sent: Sunday, November 04, 2007 11:37 PM To: M?rcio Ribeiro; r-sig-epi at stat.math.ethz.ch Subject: Re: [R-sig-Epi] Data.Frame Desaggregation Ribeiro Why not (modified df1)
df1 <- data.frame(Y=c(3,1,1,2),m=c(3,4,3,2)) df1
Y m 1 3 3 2 1 4 3 1 3 4 2 2
df1[rep(row.names(df1),rep(3,dim(df1)[1])),]
Y m
1 3 3
1.1 3 3
1.2 3 3
2 1 4
2.1 1 4
2.2 1 4
3 1 3
3.1 1 3
3.2 1 3
4 2 2
4.1 2 2
4.2 2 2
Ross Darnell
-----Original Message-----
From: r-sig-epi-bounces at stat.math.ethz.ch
[mailto:r-sig-epi-bounces at stat.math.ethz.ch] On Behalf Of
M?rcio Ribeiro
Sent: Monday, 5 November 2007 3:29 AM
To: r-sig-epi at stat.math.ethz.ch
Subject: [R-sig-Epi] Data.Frame Desaggregation
Hi Listers,
I am trying to transform the data.frame above in a more
detailed data.frame... I checked a example at the website,
but I didn't understand at all.
data.frame(x = with(df1, rep(x, m)))
What does the df1 means...
My data looks like this...
Y m X1 X2
1 3 3 12.0 0.8
2 1 4 4.1 67.5
3 1 3 2.4 12.4
4 2 2 11.2 7.7
My object is to obtain this...
Y m X1 X2
1 1 . 12.0 0.8
1 1 . 12.0 0.8
1 1 . 12.0 0.8
2 1 . 4.1 67.5
2 0 . 4.1 67.5
2 0 . 4.1 67.5
2 0 . 4.1 67.5
3 1 . 2.4 12.4
3 0 . 2.4 12.4
3 0 . 2.4 12.4
4 1 . 11.2 7.7
4 1 . 11.2 7.7
Thanks in advance,
Ribeiro
---------------------------------
[[alternative HTML version deleted]]
_______________________________________________ R-sig-Epi at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-epi _______________________________________________ R-sig-Epi at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-epi