Create sequence of repeated values, in sequence?
You missed the each= argument to rep(): R> n <- 3 R> rep(1:5, each=n) [1] 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 R> so your example can be done with a simple R> rep(1:8, each=20)
You missed the each= argument to rep(): R> n <- 3 R> rep(1:5, each=n) [1] 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 R> so your example can be done with a simple R> rep(1:8, each=20)
You can also write: [e] * n You should note that if e is for example an empty list you get a list with n references to the same list, not n independent empty lists. Performance testing At first glance it seems that repeat is the fastest way to create a list with n identical … Read more
old question, new verb in tidyverse: library(tidyr) # version >= 0.8.0 df <- data.frame(var1=c(‘a’, ‘b’, ‘c’), var2=c(‘d’, ‘e’, ‘f’), freq=1:3) df %>% uncount(freq) var1 var2 1 a d 2 b e 2.1 b e 3 c f 3.1 c f 3.2 c f