View source: R/dthelper-data-wrangling.R
multi.spread | R Documentation |
Wrangles data from long to wide form
multi.spread(df, id, key, var = NULL, sep = "_", custom.append = NULL)
df |
data.frame object |
id |
Identifier variable. Input as string |
key |
Key variable to spread on. Input as string |
var |
Variables being spread. Defaults to all other variables (apart from id and key) |
sep |
Separator that appends to variable names after being spread |
custom.append |
Customised labels that are appended to variable names. Length should match number of unique keys |
data.frame object
df <- data.frame( id = c(1,1,1,2,2,2,3,3,3), time = c(1,2,3,1,2,3,1,2,3), v1 = 1:9, v2 = 11:19, v3 = paste0("a",1:9) ) df.wide <- multi.spread(df, id = "id", key = "time") df.wide <- multi.spread(df, id = "id", key = "time", custom.append = c("t1","t2","t3")) df.wide <- multi.spread(df, id = "id", key = "time", var = c("v1","v2"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.