Unpivot column data from wide format to long format.
Usage
melt(object, ...)
# S4 method for class 'DFrame'
melt(object, colnames = c("rowname", "colname", "value"))
# S4 method for class 'matrix'
melt(
object,
colnames = c("rowname", "colname", "value"),
min = -Inf,
minMethod = c("absolute", "perRow"),
trans = c("identity", "log2", "log10")
)
# S4 method for class 'table'
melt(object, ...)Arguments
- object
Object.
- colnames
character(3). Column name mappings for melted data frame return.- min
numeric(1)orNULL. Minimum count threshold to apply. Filters using "greater than or equal to" logic internally. Note that this threshold gets applied prior to logarithmic transformation, whentransargument applies. Use-InforNULLto disable.- minMethod
character(1). Only applies whenminargument is numeric. Usesmatch.arg().absolute: Applies hard cutoff tocountscolumn 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.
See also
https://seananderson.ca/2013/10/19/reshape/
reshape2::melt(deprecated).Python
pandas.melt.
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