reshape2 (version 1.4.2) Melt a data frame into form suitable for easy casting.


You need to tell melt which of your variables are id variables, and which are measured variables. If you only supply one of id.vars and measure.vars, melt will assume the remainder of the variables in the data set belong to the other. If you supply neither, melt will assume factor and character variables are id variables, and all others are measured.


"melt"(data, id.vars, measure.vars, = "variable", ..., na.rm = FALSE, = "value", factorsAsStrings = TRUE)


data frame to melt
vector of id variables. Can be integer (variable position) or string (variable name). If blank, will use all non-measured variables.
vector of measured variables. Can be integer (variable position) or string (variable name)If blank, will use all non id.vars
name of variable used to store measured variable names
further arguments passed to or from other methods.
Should NA values be removed from the data set? This will convert explicit missings to implicit missings.
name of variable used to store values
Control whether factors are converted to character when melted as measure variables. When FALSE, coercion is forced if levels are not identical across the measure.vars.

See Also


Other melt methods: melt.array, melt.default, melt.list


Run this code
names(airquality) <- tolower(names(airquality))
melt(airquality, id=c("month", "day"))
names(ChickWeight) <- tolower(names(ChickWeight))
melt(ChickWeight, id=2:4)

Run the code above in your browser using DataCamp Workspace