Skip to contents

Unpivot column data from wide format to long format.

Usage

melt(object, ...)

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

Arguments

object

Object.

assay

vector(1). Assay name or index position.

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

See also

Examples

data(SingleCellExperiment_splatter, package = "AcidTest")

## SingleCellExperiment ====
object <- SingleCellExperiment_splatter
dim(object)
#> [1] 100 400
df <- melt(object)
nrow(df)
#> [1] 40000
print(df)
#> DataFrame with 40000 rows and 6 columns
#>       rowname colname value sampleId sampleName interestingGroups
#>         <Rle>   <Rle> <Rle>    <Rle>      <Rle>             <Rle>
#> 1     gene001 cell001   172  sample3    sample3           sample3
#> 2     gene002 cell001  1377  sample3    sample3           sample3
#> 3     gene003 cell001    29  sample3    sample3           sample3
#> 4     gene004 cell001     3  sample3    sample3           sample3
#> 5     gene005 cell001   376  sample3    sample3           sample3
#> ...       ...     ...   ...      ...        ...               ...
#> 39996 gene096 cell400    57  sample2    sample2           sample2
#> 39997 gene097 cell400   198  sample2    sample2           sample2
#> 39998 gene098 cell400     9  sample2    sample2           sample2
#> 39999 gene099 cell400  4724  sample2    sample2           sample2
#> 40000 gene100 cell400  1185  sample2    sample2           sample2