Learn R Programming

reshape (version 0.8.9)

melt.data.frame: Melt a data frame

Description

Melt a data frame into form suitable for easy casting.

Usage

# S3 method for data.frame
melt(data, id.vars, measure.vars,
  variable_name = "variable", na.rm = !preserve.na, preserve.na = TRUE, ...)

Arguments

data

Data set to melt

id.vars

Id variables. If blank, will use all non measure.vars variables. Can be integer (variable position) or string (variable name)

measure.vars

Measured variables. If blank, will use all non id.vars variables. Can be integer (variable position) or string (variable name)

variable_name

Name of the variable that will store the names of the original variables

na.rm

Should NA values be removed from the data set?

preserve.na

Old argument name, now deprecated

...

other arguments ignored

Value

molten data

Details

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.

See Also

http://had.co.nz/reshape/

Examples

Run this code
# NOT RUN {
head(melt(tips))
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 DataLab