melt.data.frame {reshape2}R Documentation

Melt a data frame into form suitable for easy casting.

Description

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.

Usage

  ## S3 method for class 'data.frame'
 melt(data, id.vars, measure.vars,
    variable.name = "variable", ..., na.rm = FALSE,
    value.name = "value")

Arguments

data

data frame to melt

id.vars

vector of id variables. Can be integer (variable position) or string (variable name)If blank, will use all non-measured variables.

measure.vars

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

variable.name

name of variable used to store measured variable names

value.name

name of variable used to store values

na.rm

Should NA values be removed from the data set? This will convert explicit missings to implicit missings.

...

further arguments passed to or from other methods.

Examples

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

[Package reshape2 version 1.2.2 Index]