[R] Select fixed number of elements

Gerrit Eichner Gerrit.Eichner at math.uni-giessen.de
Wed Oct 30 09:41:02 CET 2013


Hello, Alaois,

if x is your vector maybe

n <- length( x)
positions <- trunc( quantile( seq( n), prob = 0:5/5))
x[ positions]

comes close to what you want.

  Hth  --  Gerrit

> Hi all, I have in my code some vectors that are not of equal size. I 
> would like to be able for each of these vectors select 6 elements that 
> are (almost) equally spaced. So the first one would be at (or close) to 
> the beginning the last one at (or close) to the end and the other 4 
> equally spaced between first and last element.
>
> How can I do something like that on a vector of not known size?
>
> I would like to thank you in advance for your help
>
> Regards
> Alex
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list