0

Say we have a vector like the one below:

countries <- c("UK", "Germany", "Italy", "Denmark")

I would like to create another one out of this, but longer like the following one:

countries_long <- c("UK", "UK", "UK", "UK", "Germany", "Germany", "Italy", "Italy", "Denmark", "Denmark", "Denmark")

How could I achieve this outcome?

teogj
  • 289
  • 1
  • 11

1 Answers1

1
> rep(countries, c(4,2,2,3))
 [1] "UK"      "UK"      "UK"      "UK"      "Germany" "Germany" "Italy"   "Italy"   "Denmark" "Denmark" "Denmark"
> 
Karthik S
  • 11,348
  • 2
  • 11
  • 25