| reshape1 {reshape} | R Documentation |
Takes data frame and variable list and casts data.
reshape1(data, rows = NULL, cols = NULL, fun.aggregate, margins, ...)
data |
data frame |
rows |
variables to appear in columns |
cols |
variables to appear in rows |
fun.aggregate |
aggregation function |
margins |
vector of variable names (can include "grand_col" and "grand_row") to compute margins for, or TRUE to computer all margins |
... |
further arguments are passed to aggregating function |
Hadley Wickham <h.wickham@gmail.com>
names(airquality) <- tolower(names(airquality))
airquality.d <- melt(airquality, id=c("month", "day"))
#Basic call
reshape1(airquality.d, c("month"), , mean)
reshape1(airquality.d, c("month"), "variable", mean)
reshape1(airquality.d, c("day"), "month", mean)
#Explore margins
reshape1(airquality.d, c("month"), , mean, "month")
reshape1(airquality.d, c("month"), , mean, "grand_col")
reshape1(airquality.d, c("month"), , mean, "grand_row")
reshape1(airquality.d, c("month", "day"), , mean, "month")
reshape1(airquality.d, c("month"), "variable", mean, "month")
reshape1(airquality.d, c("variable"), "month", mean, "month")
reshape1(airquality.d, c("month"), "variable", mean, c("month","variable"))
reshape1(airquality.d, c("month"), "variable", mean, c("grand_row"))
reshape1(airquality.d, c("month"), "variable", mean, c("grand_col"))
reshape1(airquality.d, c("month"), "variable", mean, c("grand_row","grand_col"))
reshape1(airquality.d, c("variable","day"),"month", mean,c("variable"))
reshape1(airquality.d, c("variable","day"),"month", mean,c("variable","grand_row"))
reshape1(airquality.d, c("month","day"), "variable", mean, "month")
# Multiple fnction returns
reshape1(airquality.d, c("month", "result_variable"), , range)
reshape1(airquality.d, c("month"),"result_variable" , range)
reshape1(airquality.d, c("result_variable", "month"), , range)
reshape1(airquality.d, c("month", "result_variable"), "variable", range, "month")
reshape1(airquality.d, c("month", "result_variable"), "variable", range, "variable")
reshape1(airquality.d, c("month", "result_variable"), "variable", range, c("variable","month"))
reshape1(airquality.d, c("month", "result_variable"), "variable", range, c("grand_col"))
reshape1(airquality.d, c("month", "result_variable"), "variable", range, c("grand_row"))
reshape1(airquality.d, c("month"), c("variable"), function(x) diff(range(x)))