melt.long: Transform data.frame to Long Form

Description Usage Arguments Details Value Author(s) Examples

View source: R/melt.long.R

Description

The function transforms a given data.frame form wide to long form.

Usage

1
melt.long(data, select, group)

Arguments

data

data.frame that shall be transformed.

select

optional integer vector to select a subset of the columns of data.

group

optional vector to include an additional grouping in the output; for more details see examples below.

Details

The function transforms a given data.frame form wide to long form. This is for example useful for plotting with ggplot2.

Value

data.frame in long form.

Author(s)

Matthias Kohl Matthias.Kohl@stamats.de

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
library(ggplot2)
## some random data
test <- data.frame(x = rnorm(10), y = rnorm(10), z = rnorm(10))
test.long <- melt.long(test)
test.long
ggplot(test.long, aes(x = variable, y = value)) +
  geom_boxplot(aes(fill = variable))
## introducing an additional grouping variable
group <- factor(rep(c("a","b"), each = 5))
test.long.gr <- melt.long(test, select = 1:2, group = group)
test.long.gr
ggplot(test.long.gr, aes(x = variable, y = value, fill = group)) +
  geom_boxplot()

MKmisc documentation built on Aug. 8, 2021, 5:06 p.m.