[R] Manipulation of data.frame into an array

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Thu May 24 16:54:36 CEST 2018


Hello,

I am not sure I understand the question, but see if the following is 
what you want.

split(Imputed, cumsum(c(0, diff(Imputed$Y) != 1)))


Hope this helps,

Rui Barradas

On 5/24/2018 3:46 PM, Ioanna Ioannou wrote:
> Hello everyone,
> 
> 
>   I want to transform a data.frame into an array (lets call it mydata), where: mydata[[1]] is the first imputed dataset...and for each mydata[[d]], the first p columns are covariates X, and the last one is the outcome Y.
> 
> 
> Lets assume a simple data.frame:
> 
> 
> Imputed = data.frame( X1 = c(1,2,1,2,1,2,1,2, 1,2,1,2,1,2,1,2),
> 
>                                            X2 = c(0,1,0,1,1,1,0,1, 0,1,0,1,1,1,0,1),
> 
>                                             Y   = c(1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8))
> 
> The first 8 have been obtained by the first imputation and the later 8 by the 2nd.
> 
> 
> Can you help me please?
> 
> 
> Best,
> 
> ioanna
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>




More information about the R-help mailing list