1

In R, I need to create a vector in which the values appear in order, starting with 1, in which each value is duplicated once, as shown below: v <- c(1,1,2,2,3,3,4,4,5,5) and so on.

The above vector has five pairs, but the number of pairs can be many more.

How can I do that without having to manually type every pair?

markus
  • 25,843
  • 5
  • 39
  • 58
Metsfan
  • 510
  • 2
  • 8

1 Answers1

1

You can just do:

rep(1:10, each = 2)

[1]  1  1  2  2  3  3  4  4  5  5  6  6  7  7  8  8  9  9 10 10
tmfmnk
  • 38,881
  • 4
  • 47
  • 67