问题
I'm wondering if there is a simpler way to make a list with, for example 10 '4', 20 '6' and 30 '3' then writing it by hand (example <- c(4,4,4,4,...)
) with the function 'rep'. I know i can repeat a certain sequence n times and each by n times too, but i don't know how can i make one with different amounts of each number.
回答1:
Just use rep
with both arguments being the desired vectors:
x <- rep(c(4, 6, 3), c(10, 20, 30))
table(x)
3 4 6
30 10 20
来源:https://stackoverflow.com/questions/49557890/r-make-a-repetitive-sequence-with-rep