slice-ranges: Choose rows by their position

Description Usage Arguments Value Examples

Description

Choose rows by their position

Usage

1
2
3
4
5
6
7
8
## S3 method for class 'Ranges'
slice(.data, ..., .preserve = FALSE)

## S3 method for class 'GroupedGenomicRanges'
slice(.data, ..., .preserve = FALSE)

## S3 method for class 'GroupedIntegerRanges'
slice(.data, ..., .preserve = FALSE)

Arguments

.data

a Ranges object

...

Integer row values indicating rows to keep. If .data has been grouped via group_by(), then the positions are selected within each group.

.preserve

when FALSE (the default) the grouping structure is recomputed, otherwise it is kept as is. Currently ignored.

Value

a GRanges object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
df <- data.frame(start = 1:10,
                 width = 5,
                 seqnames = "seq1",
                 strand = sample(c("+", "-", "*"), 10, replace = TRUE),
                 gc = runif(10))
rng <- as_granges(df)
dplyr::slice(rng, 1:2)
dplyr::slice(rng, -n())
dplyr::slice(rng, -5:-n())

by_strand <- group_by(rng, strand)

# slice with group by finds positions within each group
dplyr::slice(by_strand, n())
dplyr::slice(by_strand, which.max(gc))

# if the index is beyond the number of groups slice are ignored
dplyr::slice(by_strand, 1:3)

plyranges documentation built on Nov. 8, 2020, 7:36 p.m.