Re: [R] Successive subsets from a vector?

From: Charles C. Berry <cberry_at_tajo.ucsd.edu>
Date: Wed 23 Aug 2006 - 03:13:19 EST

Like this:
> do.call( paste, c( list(sep=""), lapply(1:5,function(x) VECTOR[x:(length(VECTOR)-5+x)]) ))
[1] "14265" "42650" "265011" "6501110" "5011104" "0111043" "1110436" "104368" "43686"
>

HTH, Chuck

On Tue, 22 Aug 2006, kone wrote:

> I'd like to pick every imbricated five character long subsets from a
> vector. I guess there is some efficient way to do this without loops...
> Here is a for-loop-version and a model for output:
>
> VECTOR=c(1,4,2,6,5,0,11,10,4,3,6,8,6);
>
> ADDRESSES=c();
> for(i in 1:(length(VECTOR)-4)){
> ADDRESSES[i]=paste(VECTOR[i:(i+4)],collapse="")
> }
>
> > ADDRESSES
> [1] "14265" "42650" "265011" "6501110" "5011104" "0111043"
> "1110436" "104368"
> [9] "43686"
>
>
> Atte Tenkanen
> University of Turku, Finland
>
> [[alternative text/enriched version deleted]]
>
>
>
> [ Part 3.64: "Included Message" ]
>

Charles C. Berry                        (858) 534-2098
                                          Dept of Family/Preventive Medicine
E mailto:cberry@tajo.ucsd.edu	         UC San Diego
http://biostat.ucsd.edu/~cberry/         La Jolla, San Diego 92093-0717

______________________________________________
R-help@stat.math.ethz.ch 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. Received on Wed Aug 23 04:31:23 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 23 Aug 2006 - 06:21:38 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.