Yep I did some mistake while I was typing the example What I want is this one cbind(2^(0:(n-1))) and the problem is that at the last "window" this is going to explode are there will be less elements than what the window asks for.
How should I deal with that? Regards Alex ________________________________ From: David Winsemius <dwinsem...@comcast.net> Cc: R help <R-help@r-project.org> Sent: Saturday, March 10, 2012 2:49 PM Subject: Re: [R] Window on a vector On Mar 10, 2012, at 7:44 AM, Alaios wrote: > Dear all, > I have a large vector (lets call it myVector) and I want to plot its value > with the logic below > > yaxis<-myVector[1] > yaxis<-c(xaxis,mean(myvector[2:3]) > yaxis<-c(xaxis,mean(myvector[4:8]) > yaxis<c(xaxis,mean(myvector[9:16]) > yaxis<c(xaxis,mean(myvector[17:32]) > > this has to stop when the new ..... yaxis<c(xaxis,mean(myvector[1024:2048]) > will not find the correspondent number of elements, either wise it will stop > with an error. > > > How I can do something like that in R? This will generate two series that are somewhat like your index specification. I say "somewhat" because you appear to have changed the indexing strategy in the middle. You start with 2^0. 2^1 and 2^2 as you "begin" but then switch to 2^3+1, and 2^4+1. n=20 cbind(2^(0:(n-1)), 2^(1:n)-1) You can decide what to use for n with logic like: which.max(20 >= 2^(1:10) ) Then you can use sapply or mapply. > Alex > [[alternative HTML version deleted]] Please learn to post in plain text. -- David Winsemius, MD West Hartford, CT [[alternative HTML version deleted]]
______________________________________________ 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.