[R] repeating values in an index two by two

Patrick Burns pburns at pburns.seanet.com
Mon Nov 11 16:14:39 CET 2013


 > f1
function(x) {
     one <- matrix(1:x, nrow=2)
     as.vector(rbind(one, one))
}
<environment: 0x000000000daaf1c0>
 > f1(8)
  [1] 1 2 1 2 3 4 3 4 5 6 5 6 7 8 7 8

Pat


On 11/11/2013 12:11, Federico Calboli wrote:
> Hi All,
>
> I am trying to create an index that returns something like
>
> 1,2,1,2,3,4,3,4,5,6,5,6,7,8,7,8
>
> and so on and so forth until a predetermined value (which is obviously even).  I am trying very hard to avoid for loops or for loops front ends.
>
> I'd be obliged if anybody could offer a suggestion.
>
> BW
>
> F
>
>
>
> ______________________________________________
> 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.
>

-- 
Patrick Burns
pburns at pburns.seanet.com
twitter: @burnsstat @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of:
  'Impatient R'
  'The R Inferno'
  'Tao Te Programming')



More information about the R-help mailing list