rstudio - Add values to a vector to make a consecutive vector in R -


i have several vectors this:

v1 <- c(1,2,4) v2 <- c(3,5,8) v3 <- c(4) 

this small sample of them. i'm trying figure out way add values each of them make them consecutive vectors. @ end, this:

v1 <- c(1,2,3,4) v2 <- c(1,2,3,4,5,6,7,8) v3 <- c(1,2,3,4) 

so "3" added first vector, "1","2","4","6","7" added second , forth. have several hundred vectors i'm trying figure out solution scale/be automated.

you can use seq , max

  seq(max(v1)) 

for multiple vectors, can loop

 lapply(mget(paste0('v',1:3)), function(x) seq(max(x)))  #$v1  #[1] 1 2 3 4   #$v2  #[1] 1 2 3 4 5 6 7 8   #$v3  #[1] 1 2 3 4 

Comments