json - How to join nested values into one column with tidyjson? -
i want join 2 values in 1 column instead of spreading
'{"name": {"first": "bob", "last": "jones"}, "age": 32}' %>% spread_values( first.name = jstring("name", "first"), age = jnumber("age") ) %>% unite(conc, c("first.name", "age"), sep=" ") but keep having following error
all select() inputs must resolve integer column positions. following not: c("first.name", "age")
my desire output have 1 new column "conc" replacing both first.name , age , concatenate every string value. such "jones 32"
which weird because if remove last line gives me proper data.frame , can access first.name , age.
any hint?
though tbl_json objects inherit tbl_df, not play nicely once done parsing , begin further manipulation in tidyjson , dplyr. reason have additional methods , attributes tagging along not necessary anymore.
as result, once finished parsing, habit use tbl_df or as_data_frame strip off tbl_json component of object. prefer tbl_df because shorter.
i using development version github: devtools::install_github('jeremystan/tidyjson')
i not reproduce error mention, seems work:
library(tidyjson) library(tidyr) "{\"name\": {\"first\": \"bob\", \"last\": \"jones\"}, \"age\": 32}" %>% spread_values(first.name = jstring("name","first") , age = jnumber("age") ) %>% tbl_df() %>% unite(conc, c("first.name", "age"), sep = " ") #> # tibble: 1 x 2 #> document.id conc #> * <int> <chr> #> 1 1 bob 32 other food thought when concatenating strings use paste() or paste0() within mutate. mutate supported tidyjson, well, can used in pipeline while parsing json. paste(.,collapse=',') can helpful when aggregating multiple rows summarize, too.
Comments
Post a Comment