Use tail and head. See interspersed. On Thu, Dec 11, 2008 at 9:45 PM, Mike Rowe <mwr...@gmail.com> wrote: > Greetings! > > I come to R by way of Matlab. One feature in Matlab I miss is its > "end" keyword. When you put "end" inside an indexing expression, it > is interpreted as the length of the variable along the dimension being > indexed. For example, if the same feature were implemented in R: > > my.vector[5:end]
tail(my.vector, -4) > > would be equivalent to: > > my.vector[5:length(my.vector)] > > or: > > this.matrix[3:end,end] tail(tail(this.matrix, -2), 1) > > would be equivalent to: > > this.matrix[3:nrow(this.matrix),ncol(this.matrix)] # or > this.matrix[3:dim(this.matrix)[1],dim(this.matrix)[2]] > > As you can see, the R version requires more typing, and I am a lousy > typist. > > With this in mind, I wanted to try to implement something like this in > R. It seems like that in order to be able to do this, I would have to > be able to access the parse tree of the expression currently being > evaluated by the interpreter from within my End function-- is this > possible? Since the "[" and "[[" operators are primitive I can't see > their arguments via the call stack functions... > > Anyone got a workaround? Would anybody else like to see this feature > added to R? > > Thanks, > Mike > > ______________________________________________ > 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.