reorganise | R Documentation |
This function takes a disorganised messy table and rearranges columns and rows into a tidy table based on a schema description.
reorganise(input = NULL, schema = NULL)
input |
[ |
schema |
[ |
A (tidy) table which is the result of reorganising input
based
on schema
.
# a rather disorganised table with messy clusters and a distinct variable (input <- tabs2shift$clusters_messy) # put together schema description by ... # ... identifying cluster positions schema <- setCluster(id = "territories", left = c(1, 1, 4), top = c(1, 8, 8)) # ... specifying the cluster ID as id variable (obligatory) schema <- schema %>% setIDVar(name = "territories", columns = c(1, 1, 4), rows = c(2, 9, 9)) # ... specifying the distinct variable (explicit position) schema <- schema %>% setIDVar(name = "year", columns = 4, rows = c(3:6), distinct = TRUE) # ... specifying a tidy variable (by giving the column values) schema <- schema %>% setIDVar(name = "commodities", columns = c(1, 1, 4)) # ... identifying the (tidy) observed variables schema <- schema %>% setObsVar(name = "harvested", columns = c(2, 2, 5)) %>% setObsVar(name = "production", columns = c(3, 3, 6)) # get the tidy output reorganise(input, schema)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.