Reputation: 285
This is my first question I ever raised to this community, I hope I could resolve my doubt by communicating great experienced people over here. I have three group where each contains 3 different data.frame objects with different length and dimension. I want to some sort of manipulation that group them by specific data.frame objects. I think group_by from dply package may do this task, but I am not sure for this and even I have not perfectly known of using dplyr packages, so please give your contribution on my question. Thanks everyone.
Here is simple reproducible example to make my question clear:
group1 <- list(a1 <- iris[1:10,],
b1 <- airquality[1:20,],
c1 <- cars[1:20,])
group2 <- list(a2 <- iris[15:35,],
b2 <- airquality[10:25,],
c2 <- cars[15:30,])
group3 <- list(a3 <- iris[40:60,],
b3 <- airquality[30:50,],
c3 <- cars[25:45,])
imagine group1, group2, group3 are placed in three different directory in R memory, so I want to acess each group simultaneously, and group them by specific data.frame objects. So this is my expected output:
group_a <- list(a1, a2, a3)
group_b <- list(b1, b2, b3)
group_c <- list(c1, c2, c3)
To be clear, my reproducible example simulated based on the result of function that I implemented, every time I execute my function it return result as list and store them in different R directory, that's why I need to access each group of result same time, and group them what I expected. Can any experienced member give some idea how to achieve my expected result respect to problem that I stated? I am thankful everyone who try to help here.
Best
Jeff
Upvotes: 2
Views: 160
Reputation: 887511
We can use transpose
from purrr
after placing the group datasets in a list
library(purrr)
lst <- transpose(list(group1, group2, group3))
group1New <- lst[[1]]
group2New <- lst[[2]]
group3New <- lst[[3]]
Upvotes: 3