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

Tidyr use? #55

Open
havlikp opened this issue Mar 21, 2017 · 1 comment
Open

Tidyr use? #55

havlikp opened this issue Mar 21, 2017 · 1 comment

Comments

@havlikp
Copy link

havlikp commented Mar 21, 2017

Hi, first of all - thank you for the amazing package, it made my life so much simpler! I ended stuck with one simple use-case though - is there a way to convert DataFrame with JSON object to a simple DataFrame, so that Tidyr package is fully compatible? I couldn't use spread() function in one of my solutions, and ended up unlisting the DataFrame with:

final-data <- data.frame(lapply(data.frame(t(lapply(df_json, [))), unlist))

Any tips / suggestions? Could I wrap tidyr verbs just as dplyr can be applied?

@colearendt
Copy link

Hello! I recommend looking at the more up-to-date repo here. There are some helpful additional tools that have not yet made it to CRAN, if you are willing to install the dev version with devtools::install_github('jeremystan/tidyjson)`.

In any case, the simplest solution I have seen to your problem (that should work in the CRAN version of tidyjson too, I believe) is:

library(dplyr)
library(tidyjson)

## tbl_df at present drops the tbl_json components of the object
## so you are ready for working within tidyr
final-data <- myjson %>% as.tbl_json %>% tbl_df

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants