[R-sig-Epi] Data.Frame Desaggregation
Ross Darnell
r.darnell at uq.edu.au
Sun Nov 4 23:37:11 CET 2007
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
More information about the R-sig-Epi
mailing list