Pregunta

I'm new to r, and I'm having difficulties in understanding what how the start and end parameter work if provided as vectors. Consider the code:

x <- c(4,6,5,4,6,2,6,7,5,5)
seqselect(x, start=6, end=10)

This return a vector with the integers from positions 6 to 10. Now:

seqselect(x, start=c(6,1), end=c(10,5))

Returns values 6-10 concatenated with values from 1-5. Why is that so? What does the second value from the vector in start/end do? Example from: IRanges Overview page 2

¿Fue útil?

Solución

You misread the example code. It actually says:

seqselect(x, start=c(6,1), end=c(10,5))
# ---------------------^ 1, not 2!

… and of course that does exactly what the function says: it concatenates several subranges – in that case, the subranges [6, 10] and [1, 5].

In other words, seqselect takes a number of N start and end points and for each of the i ∈ 1…N paired start and end points, it extracts the range [starti, endi].

The seqselect arguments are admittedly a bit weird (I would even say the function is badly designed). It would be much more logical to specify this request as

seqselect(x, (6, 10), (1, 5))

… i.e. giving each range explicitly.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top