Skip to contents

Unpivot column data from wide format to long format.

Usage

melt(object, ...)

# S4 method for DFrame
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 table
melt(object, ...)

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 2023-04-27.

See also

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