[R] ddply (or other suitable solution) question
Bert Gunter
bgunter@4567 @end|ng |rom gm@||@com
Thu Sep 13 22:40:39 CEST 2018
What if there is only one read in the id?
Bert Gunter
"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Thu, Sep 13, 2018 at 12:11 PM Andras Farkas via R-help
<r-help using r-project.org> wrote:
>
> Dear All,
>
> I have data frame:
> set.seed(123.456)
> df <-data.frame(ID=c(1,1,2,2,2,3,3,3,3,4,4,5,5),
> read=c(1,1,0,1,1,1,0,0,0,1,0,0,0),
> int=c(1,1,0,0,0,1,1,0,0,1,1,1,1),
> z=rnorm(13,1,5),
> y=rnorm(13,1,5))
>
> what I would like to achieve (as best as I see it now) is to create multiple lists (and lists within lists using the data in df) that would be based on the groups in the ID column ("top level of list") and "join together" each line item within the group followed by the next line item ("bottom level list"), so would look like this for
>
> [[ID=1]]
> [[1]][[1]]
> ID read int z y
> 1 1 1 5.188935 5.107905
> 1 1 1 1.766866 4.443201
> [[ID=2]]
> [[2]][[1]] ID read int z y
> 2 0 0 -4.690685 3.7695883
> 2 1 0 7.269075 0.6904414[[ID=2]]
> [[2]][[2]] ID read int z y
> 2 1 0 7.269075 0.6904414
> 2 1 0 3.132321 -0.5298133[[ID=3]]
> [[3]][[1]] ID read int z y
> 3 1 1 -0.4753574 -0.902355
> 3 0 1 5.4756283 -2.473535
> [[ID=3]]
> [[3]][[2]]
> 3 0 1 5.475628 -2.47353489
> 3 0 0 5.390667 -0.03958639
>
>
> hoping example clear enough... all our help is appreciated,
>
> thanks,
>
>
>
> Andras
>
> ______________________________________________
> 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