[R] extract vector elements of unknown range

Sepp Tannhuber sepp.tannhuber at yahoo.de
Sat Aug 25 00:23:05 CEST 2012


Dear all,

I have two vectors
  x <- c(1:20)
  y <- c(1,5,10,14)

Now I would like to extract
  x[ (y[n] + 2):(y[n+1] - 1) ]
for all elements except last one in y. This means I want to have
  x[ c( (y[1]+2):(y[2]-1), (y[2]+2):(y[3]-1), (y[3]+2):(y[4]-1) ) ]
How is this possible if y is a vector of unknown length?

Best regards
Joseph



More information about the R-help mailing list