expand_integer_json | R Documentation |
This function accepts a data.table
along with a set of grouping variables and a character-format integer-style JSON column (i.e. starts with square brackets, not curly).
expand_integer_json( dt, expand, index = "index", by = NULL, fast = TRUE, fun = sum, na.rm = TRUE, set_key = TRUE )
dt |
data.table object (or something that can be coerced to data.table) |
expand |
String indicating the JSON column to be expanded. |
index |
String indicating the name of the new index column |
by |
Character vector indicating the variables to group by after expanding. Set to |
fast |
Assumes that all the JSON vectors are of equal length, and adds the values together rather than using whatever is in |
fun |
Function that takes a vector and returns a single value to use when collapsing to the |
na.rm |
Ignore missing values of |
set_key |
Set the key of |
It expands that JSON column into long format, with one row per observation per value of the JSON column, and then collapses everything according to the set of grouping variables.
# Example data patterns <- data.table::data.table(state_fips = c(1,1,2,2), int_origin = c('[2,3]', '[3,4]', '[4,5]', '[5,6]')) expand_integer_json(patterns, 'int_origin', by = 'state_fips')[]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.