Description Usage Arguments Details Value References Examples
Wraps the function base::reshape()
to mimic the behavior of the
Stata reshape
. Used to transform data.frames between "wide" and
"long" formats.
1 2 3 | wide_to_long(data, stub, i, j, clean = TRUE)
long_to_wide(data, stub, i, j, clean = TRUE)
|
data |
a |
stub |
a character string. For |
i |
a string. The name of the column in |
j |
a string. For |
clean |
a logical value. If TRUE, the resulting |
wide_to_long()
and long_to_wide()
are designed to
closely mimic basic functionality of Stata's reshape
command. See
the examples below for intended usage.
a data.frame
.
http://www.stata.com/manuals13/dreshape.pdf
1 2 3 4 5 6 7 8 9 10 11 | t <- "id,sex,inc80,inc81,inc82
1,0,5000,5500,6000
2,1,2000,2200,3300
3,0,3000,2000,1000"
df1 <- read.csv(text = t)
df2 <- wide_to_long(data = df1, stub = "inc", i = "id", j = "year")
df3 <- long_to_wide(data = df2, stub = "inc", i = "id", j = "year")
identical(df1, df3)
df4 <- long_to_wide(data = df2, stub = "inc", i = "id", j = "year",
clean = FALSE)
identical(df1, df4)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.