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

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

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

...

Additional arguments.

Value

DataFrame.

Note

Updated 2021-09-03.

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(matrix, package = "AcidTest") ## matrix ==== dim(matrix)
#> [1] 4 4
x <- melt(matrix) dim(x)
#> [1] 16 3
print(x)
#> DataFrame with 16 rows and 3 columns #> rowname colname value #> <factor> <factor> <integer> #> 1 gene01 sample01 1 #> 2 gene02 sample01 5 #> 3 gene03 sample01 9 #> 4 gene04 sample01 13 #> 5 gene01 sample02 2 #> ... ... ... ... #> 12 gene04 sample03 15 #> 13 gene01 sample04 4 #> 14 gene02 sample04 8 #> 15 gene03 sample04 12 #> 16 gene04 sample04 16