[Rd] Add first() and last() to utils?
greg at warnes.net
Tue Apr 28 21:11:12 CEST 2015
I've been using first() and last() for some time instead of x and
x[length(x)] for vectors, and I gradually added methods for lists,
matrices, and data.frames.
In preparing the next release of the 'gdata' package (2.16.1) I settled on
these definitions, which harness the existing methods for head() and tail():
# Simply call 'first' or 'last' with a different default value for 'n'.
first <- function(x, n=1, ...) head(x, n=n, ...)
last <- function(x, n=1, ...) tail(x, n=n, ...)
This works nicely, but Brian noted that packages 'data.table' and 'xts'
also provide functions/S3 methods for head() and/or tail().
Would it make sense to add these definitions to package 'utils' to make
them generally available?
"Whereas true religion and good morals are the only solid foundations of
public liberty and happiness . . . it is hereby earnestly recommended to
the several States to take the most effectual measures for the
encouragement thereof." Continental Congress, 1778
[[alternative HTML version deleted]]
More information about the R-devel