'Using rep to create an ID column
I need to rep a sequence that has the following format:
1, 1, 2, 2, 3, 3,
4, 4, 4, 5, 5, 5, 6, 6, 6,
7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, etc.
I can do something similar to this with:
test<- as.data.frame(rep.int(1:9, rep(1:3, each = 3)))
But this starts with one observation for the first three numbers instead of two. The final product I'm looking for is something close to:
test2<- rep.int(1:10e3, rep(1:10, each = 1e3)) # this totals to 55,000 rows
# in the correct format, but I am looking to get a total of 54,000 rows
# and I can't figure out the right combination of arguments.
Any insight anyone has would be greatly appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
