[R] Reshaping grouped data
Dimitris Rizopoulos
d.rizopoulos at erasmusmc.nl
Tue Feb 16 09:58:13 CET 2010
one approach is:
Data.long <- with(Data, data.frame(
w = c(rbind(total - cases, cases)),
y = rep(0:1, nrow(Data)),
x1 = rep(x1, each = 2),
x2 = rep(x2, each = 2)
))
I hope it helps.
Best,
Dimitris
Myrland Øystein wrote:
> Dear R-help list,
>
>
>
> I have grouped data, looking like this:
>
>
>
> cases <- c(23,12,56,81)
>
> total <- c(123,234,248,390)
>
> x1 <- c(0,0,1,1)
>
> x2 <- c(0,1,0,1)
>
>
>
> Data <- as.data.frame(cbind(cases,total,x1,x2))
>
> Data
>
>
>
> I would like to run a logistic regression with group weights on these,
> where cases and (total-cases) are equal to the group weights (w).
>
>
>
> My final data would look like:
>
>
>
> w <- c(100,23,222,12,192,56,309,81)
>
> y <- c(0,1,0,1,0,1,0,1)
>
> x1 <- c(0,0,0,0,1,1,1,1)
>
> x2 <- c(0,0,1,1,0,0,1,1)
>
>
>
> Data.long <- as.data.frame(cbind(w,y,x1,x2))
>
> Data.long
>
>
>
> Any suggestions?
>
>
>
> All the best,
>
> Oystein Myrland
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
More information about the R-help
mailing list