Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unnesting list variable with dataframes. #58

Closed
adder opened this issue Jan 30, 2015 · 3 comments

Comments

@adder
Copy link

commented Jan 30, 2015

Hi

I recently ran into the situation where I had a dplyr dataframe with one of the variables being a list variable. This list variable contained a dataframe. I wanted to unnest this collumn. Each collumn in the nested dataframes should become a separate collumn in the unnested data frame. As far as I know this is not possible in the current implementation (in straightforward way). What would be the suggested strategy to have this behaviour?

greetz

@hadley

This comment has been minimized.

Copy link
Member

commented Jan 30, 2015

Could you please provide a reproducible example?

@adder

This comment has been minimized.

Copy link
Author

commented Jan 30, 2015

off course.
I would expect that this code:

library(dplyr)
library(tidyr)
dat1 = data_frame(a = 1:3, b = 4:6)
dat2 = data_frame(c = 7:9,d = list(dat1,dat1,dat1))
unnest(dat2, d)

gives this output:

c a b
7 1 4
7 2 5
7 3 6
8 1 4
8 2 5
8 3 6
9 1 4
9 2 5
9 3 6

You would need to make the assumption that all the dataframes in the list variable are the same. A typical use case could be that on some variables in a dataframe a function is applied rowwise that gives back a dataframe. Then one would want to unnest this for easy data manipulations where also the information in the nested data frames is needed (for grouping, filtering,...)

I hope this is clear enough.

@hadley

This comment has been minimized.

Copy link
Member

commented Jan 30, 2015

Thanks, that definitely should work. I'll take a look next time I'm working on tidyr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.