Unpivot column data from wide format to long format.

melt(object, ...)

# S4 method for matrix
melt(object, colnames = c("rowname", "colname",
  "value"), min = -Inf, minMethod = c("absolute", "perRow"),
  trans = c("identity", "log2", "log10"))

# S4 method for table
melt(object, colnames = c("rowname", "colname",
  "value"))

# S4 method for Matrix
melt(object, colnames = c("rowname", "colname",
  "value"), min = -Inf, minMethod = c("absolute", "perRow"),
  trans = c("identity", "log2", "log10"))

# S4 method for DataFrame
melt(object, colnames = c("rowname", "colname",
  "value"))

# S4 method for SummarizedExperiment
melt(object, assay = 1L, min = -Inf,
  minMethod = c("absolute", "perRow"), trans = c("identity", "log2",
  "log10"))

# S4 method for SingleCellExperiment
melt(object, assay = 1L, min = -Inf,
  minMethod = c("absolute", "perRow"), trans = c("identity", "log2",
  "log10"))

Arguments

object

Object.

colnames

character(3). Column name mappings for melted data frame return. Currently only applies to matrix and DataFrame methods. Standardized for SummarizedExperiment and SingleCellExperiment.

min

numeric(1) or NULL. Minimum count threshold to apply. Filters using "greater than or equal to" logic internally. Note that this threshold gets applied prior to logarithmic transformation, when trans argument applies. Use -Inf or NULL to disable.

minMethod

character(1). Only applies when min argument is numeric. Uses match.arg().

  • absolute: Applies hard cutoff to counts column after the melt operation. This applies to all counts, not per feature.

  • perRow: Applies cutoff per row (i.e. gene). Internally, rowSums() values are checked against this cutoff threshold prior to the melt operation.

trans

character(1). Apply a log transformation (e.g. log2(x + 1L)) to the count matrix prior to melting, if desired. Use "identity" to return unmodified (default).

assay

vector(1). Assay name or index position.

...

Additional arguments.

Value

DataFrame.

Note

Updated 2019-09-15.

See also

tidyr:

methods("gather")
methods("gather_")
getS3method("gather", "data.frame", envir = asNamespace("tidyr"))
getS3method("gather_", "data.frame", envir = asNamespace("tidyr"))
tidyr:::melt_dataframe

https://github.com/tidyverse/tidyr/blob/master/src/melt.cpp https://github.com/tidyverse/tidyr/blob/master/src/RcppExports.cpp

reshape2 (deprecated):

help(topic = "melt.array", package = "reshape2")
methods("melt")
getS3method("melt", "data.array", envir = asNamespace("tidyr"))
getS3method("melt", "data.frame", envir = asNamespace("tidyr"))

Examples

data( RangedSummarizedExperiment, SingleCellExperiment, package = "acidtest" ) ## SummarizedExperiment ==== object <- RangedSummarizedExperiment dim(object)
#> [1] 500 12
x <- melt(object) nrow(x)
#> [1] 6000
#> DataFrame with 6000 rows and 6 columns #> colname rowname value condition sampleName interestingGroups #> <Rle> <Rle> <Rle> <Rle> <Rle> <Rle> #> 1 sample01 gene001 14 A sample01 A #> 2 sample01 gene002 19 A sample01 A #> 3 sample01 gene003 19 A sample01 A #> 4 sample01 gene004 107 A sample01 A #> 5 sample01 gene005 128 A sample01 A #> ... ... ... ... ... ... ... #> 5996 sample12 gene496 0 B sample12 B #> 5997 sample12 gene497 2 B sample12 B #> 5998 sample12 gene498 20 B sample12 B #> 5999 sample12 gene499 4 B sample12 B #> 6000 sample12 gene500 31 B sample12 B
## SingleCellExperiment ==== object <- SingleCellExperiment dim(object)
#> [1] 500 100
x <- melt(object) nrow(x)
#> [1] 50000
#> DataFrame with 50000 rows and 6 columns #> colname rowname value sampleID sampleName interestingGroups #> <Rle> <Rle> <Rle> <Rle> <Rle> <Rle> #> 1 cell001 gene001 50 sample1 sample1 sample1 #> 2 cell001 gene002 0 sample1 sample1 sample1 #> 3 cell001 gene003 1320 sample1 sample1 sample1 #> 4 cell001 gene004 62 sample1 sample1 sample1 #> 5 cell001 gene005 10 sample1 sample1 sample1 #> ... ... ... ... ... ... ... #> 49996 cell100 gene496 36 sample2 sample2 sample2 #> 49997 cell100 gene497 0 sample2 sample2 sample2 #> 49998 cell100 gene498 27 sample2 sample2 sample2 #> 49999 cell100 gene499 15 sample2 sample2 sample2 #> 50000 cell100 gene500 0 sample2 sample2 sample2