Check out this thread for numerous solutions: https://stat.ethz.ch/pipermail/r-help/2007-June/134557.html
On Wed, May 26, 2010 at 1:22 PM, speretti <sabrina.pere...@gmail.com> wrote: > > Hi, > > I need help to find an efficient way to transform a vector like: > > a<-c(1,1,0,1,0,0,0,1,1,1,1,0,1,0,1,1) > > in a vector that counts only di 1 elements, like: > > b<-c(1,2,0,1,0,0,0,1,2,3,4,0,1,0,1,2) > > > Thank you! > -- > View this message in context: > http://r.789695.n4.nabble.com/counts-of-a-vector-tp2232047p2232047.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. > ______________________________________________ R-help@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.