# NOT RUN {
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)
# }
Run the code above in your browser using DataLab