Skip to contents

Drop factor levels

Usage

droplevels2(x, ...)

# S4 method for DFrame
droplevels2(x)

# S4 method for Ranges
droplevels2(x)

# S4 method for Rle
droplevels2(x)

# S4 method for data.frame
droplevels2(x)

# S4 method for factor
droplevels2(x)

Arguments

x

Object.

...

Additional arguments.

Value

Modified object.

Note

Updated 2023-09-12.

Examples

data(GRanges, package = "AcidTest")

## Ranges ====
object <- GRanges
object <- droplevels2(object)
print(object)
#> GRanges object with 5 ranges and 2 metadata columns:
#>                   seqnames              ranges strand |          geneId
#>                      <Rle>           <IRanges>  <Rle> |           <Rle>
#>   ENSG00000000003        X 100627109-100639991      - | ENSG00000000003
#>   ENSG00000000005        X 100584802-100599885      + | ENSG00000000005
#>   ENSG00000000419       20   50934867-50958555      - | ENSG00000000419
#>   ENSG00000000457        1 169849631-169894267      - | ENSG00000000457
#>   ENSG00000000460        1 169662007-169854080      + | ENSG00000000460
#>                   geneName
#>                      <Rle>
#>   ENSG00000000003   TSPAN6
#>   ENSG00000000005     TNMD
#>   ENSG00000000419     DPM1
#>   ENSG00000000457    SCYL3
#>   ENSG00000000460 C1orf112
#>   -------
#>   seqinfo: 357 sequences (1 circular) from GRCh38 genome

## Rle ====
object <- factor(c("a", "a", "b", "b"), levels = c("a", "b", "c"))
object <- S4Vectors::Rle(object)
print(object)
#> factor-Rle of length 4 with 2 runs
#>   Lengths: 2 2
#>   Values : a b
#> Levels(3): a b c
object <- droplevels2(object)
print(object)
#> factor-Rle of length 4 with 2 runs
#>   Lengths: 2 2
#>   Values : a b
#> Levels(2): a b

## factor ====
object <- factor(c("a", "a", "b", "b"), levels = c("a", "b", "c"))
print(object)
#> [1] a a b b
#> Levels: a b c
object <- droplevels2(object)
print(object)
#> [1] a a b b
#> Levels: a b