R/first.R

Defines functions first last

Documented in first last

# 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, ...)

"first<-" <- function(x, n=1, ..., value )
{
  x[1:n] <- value[1:n]
  x
}

"last<-" <- function(x, n=1, ..., value )
{
  index <- seq( length(x)-n+1, length(x) )
  x[index] <- value[1:n]
  x
}

Try the gdata package in your browser

Any scripts or data that you put into this service are public.

gdata documentation built on May 2, 2019, 5:49 p.m.