-2

I have a frequency table:

# a b
# x 1
# y 2
# z 3

and I want to create a vector [x, y, y, z, z, z] based on the counts in b.

What's the most efficient way of doing this?

Thanks!

pau
  • 51
  • 1
  • 1
  • 5

1 Answers1

1

Use the rep function. I am not aware of any other method that is quicker than this.

a = c("x","y", "z") 
b = c(1,2,3)
output <- rep(a,b)
discipulus
  • 2,665
  • 3
  • 34
  • 51