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
Provide rbind solution that can add list element names as a variable in the output #22
Comments
No documentation yet, but I'm still struggling if |
Thank -- yes As a happy user of the grammar that runs through your packages, the words this task evokes for me are Morally, this operation seems like |
I think it'll be more obvious why it's called |
I have every faith that it will be the most natural thing when you're done. :) |
This is what I would imagine to be the outcome of |
FWIW, I've removed this experimental method because I'm now pretty sure it's a bad idea (and |
Hmmm, but maybe data_frame(
x = c(1, 2),
y = c(3, 4),
z = list(data_frame(a = 1), data_frame(a = 1:3))
) (and those data frames could contain lists-columns themselves, but I think you'd need a second unnest to handle that) I'm not certain whether or not this is useful (it might crop up as an alternative way of handling relational data), but it is interesting. |
Oh that's #58 |
So ... in case anyone else finds this in their search for adding a new column with By
What I gather is that (using dplyr 0.5.0) the argument bind_rows(my_list, .id = 'species') returns
P.S. thanks again for all of the great work you and your team are doing! |
Is there a solution for the cases when |
@d8aninja Do you want to make a little example that shows exactly what you mean (I'm not entirely sure) and ask it over in the tidyverse section of community.rstudio.com? This question is a good fit. |
@jennybc will do, thanks! |
On Sep 28, 2017, at 10:14 AM, Jeff ***@***.***> wrote:
Is there a solution for the cases when rbind_rows will not accomplish this task if the constituent lists are of different length? In these cases I usually appeal to do.call(rbind, df) but there is obviously no .id argument to go along with that solution...
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
The dplyr package has a `bind_rows` function. Missing items are filled with NA.
Also see: rbind.fill in plyr-pkg.
…--
David Winsemius
Alameda, CA, USA
'Any technology distinguishable from magic is insufficiently advanced.' -Gehm's Corollary to Clarke's Third Law
|
@jennybc can you show in code how this works? I tried this with throws an error:
|
The built in method that works for me was to loop through the list and add the item name as a constant column.
After that you can apply the usual do.call as following: |
Problem: you have a list of data.frames and the element names convey information. You want to row bind them together and, in the new data.frame, you want a variable for the list element each observation originated in.
Demo: fragment subset of iris into separate data.frames, stored as list.
Note: Species info carried only via list names
Simple rbind-y calls cannot recover Species:
Current workaround: prep with mapply() to restore Species, then rbind (thanks @kara_woo for this snippet)
The text was updated successfully, but these errors were encountered: