[R] Inserting a subsequence between values of a vector

Domenico Vistocco vistocco at unicas.it
Tue Dec 4 17:42:37 CET 2007


library(R.utils)
pos=which(diff(x)==1)+1
insert(x,ats=pos,rep(list(rep(0,3)),length(pos)))

domenico vistocco

Serguei Kaniovski wrote:
> Hallo,
>
> suppose I have a vector:
>
> x <- c(1,1,1,2,2,3,3,3,3,3,4)
>
> How can I generate a vector/sequence in which a fixed number of zeroes (say
> 3) is inserted between the consecutive values, so I get
>
> 1,1,1,0,0,0,2,2,0,0,0,3,3,3,3,3,0,0,0,4
>
> thanks a lot,
> Serguei
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



More information about the R-help mailing list