melt_: Make a 'Wide' data set 'Long'

Description Usage Arguments Details Examples

View source: R/melt_.R

Description

Inspired by reshape2:::melt, we melt data.frames and matrixs. This function is built for speed.

Usage

1
2
3
4
5
6
7
8
melt_(data, ...)

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

## S3 method for class 'matrix'
melt_(data, ...)

Arguments

data

The data.frame to melt.

...

Arguments passed to other methods.

id.vars

Vector of id variables. Can be integer (variable position) or string (variable name). If blank, we use all variables not in measure.vars.

measure.vars

Vector of measured variables. Can be integer (variable position) or string (variable name). If blank, we use all variables not in id.vars.

variable.name

Name of variable used to store measured variable names.

value.name

Name of variable used to store values.

Details

If items to be stacked are not of the same internal type, they will be promoted in the order logical > integer > numeric > character.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
n <- 20
tmp <- data.frame( stringsAsFactors=FALSE,
  x=sample(letters, n, TRUE),
  y=sample(LETTERS, n, TRUE),
  za=rnorm(n),
  zb=rnorm(n),
  zc=rnorm(n)
)

stopifnot(
  identical(
    melt_(tmp, id.vars=c('x', 'y')),
    melt_(tmp, measure.vars=c('za', 'zb', 'zc'))
  )
)

kevinushey/Kmisc documentation built on May 20, 2019, 9:08 a.m.