0

I'm banging my head against the wall for this. It must be so easy, but in my 7+ years of R coding I never had to do this, and I can't figure out how to do it now.

Here's a toy df:

> x <- c(1,2,3)
> y <- c(2,3,4)
> TRY <- as.data.frame(x,y)

I want to see a brand new vector (in a df or just as a vector, whatever) that has the value "1" repeated 2 times, and then "2" repeated 3 times, and then "3" repeated 4 times.

That's all I want. Can someone PLEASE help me?

I thought of melt and cast and all that, but I don't think they're what I need here.

Thanks! Divya

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
Divs
  • 137
  • 8

1 Answers1

1

Adding comment as answer to help future users.

You can get this effect using rep like so:

x <- c(1,2,3)
y <- c(2,3,4)
vec <- rep(x, y)
vec
# [1] 1 1 2 2 2 3 3 3 3
morgan121
  • 2,213
  • 1
  • 15
  • 33