It's not always true that going out of bounds in subscripting gives an error (as you seem to assert in your original post)
x <- 1:3 x[4] # No error and note that mean() has a na.rm argument. Perhaps you should construct a *reproducible* example of what you think will go wrong. Michael On Mon, Mar 12, 2012 at 11:22 AM, Alaios <ala...@yahoo.com> wrote: > 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. This doesn't seem true: x <- 1:3 x[4] # Not 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. > ______________________________________________ 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.