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 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.

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 2020-10-09.

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
print(x)
#> DataFrame with 6000 rows and 6 columns #> colname rowname value condition sampleName #> <Rle> <Rle> <Rle> <Rle> <Rle> #> 1 sample01 gene001 2 A sample01 #> 2 sample01 gene002 17 A sample01 #> 3 sample01 gene003 5 A sample01 #> 4 sample01 gene004 0 A sample01 #> 5 sample01 gene005 14 A sample01 #> ... ... ... ... ... ... #> 5996 sample12 gene496 7 B sample12 #> 5997 sample12 gene497 149 B sample12 #> 5998 sample12 gene498 1 B sample12 #> 5999 sample12 gene499 0 B sample12 #> 6000 sample12 gene500 36 B sample12 #> interestingGroups #> <Rle> #> 1 A #> 2 A #> 3 A #> 4 A #> 5 A #> ... ... #> 5996 B #> 5997 B #> 5998 B #> 5999 B #> 6000 B
## SingleCellExperiment ==== object <- SingleCellExperiment dim(object)
#> [1] 500 100
x <- melt(object) nrow(x)
#> [1] 50000
print(x)
#> DataFrame with 50000 rows and 6 columns #> colname rowname value sampleID sampleName #> <Rle> <Rle> <Rle> <Rle> <Rle> #> 1 cell001 gene001 0 sample1 sample1 #> 2 cell001 gene002 121 sample1 sample1 #> 3 cell001 gene003 0 sample1 sample1 #> 4 cell001 gene004 25 sample1 sample1 #> 5 cell001 gene005 39 sample1 sample1 #> ... ... ... ... ... ... #> 49996 cell100 gene496 0 sample2 sample2 #> 49997 cell100 gene497 0 sample2 sample2 #> 49998 cell100 gene498 0 sample2 sample2 #> 49999 cell100 gene499 0 sample2 sample2 #> 50000 cell100 gene500 121 sample2 sample2 #> interestingGroups #> <Rle> #> 1 sample1 #> 2 sample1 #> 3 sample1 #> 4 sample1 #> 5 sample1 #> ... ... #> 49996 sample2 #> 49997 sample2 #> 49998 sample2 #> 49999 sample2 #> 50000 sample2