https://github.com/cran/simecol
Raw File
Tip revision: 90383208812a70f8a3abfd44982913c1793c00be authored by Thomas Petzoldt on 12 June 2017, 19:27:11 UTC
version 0.8-9
Tip revision: 9038320
fromtoby.R
## the fromtoby-vector form is intended to give users
## a compact representation of time steps without the need to apply
## time series classes as "ts" or "zoo"
## "fromtoby" vectors are optional, ordinary sequences are possible too

## check for from-to-by structure of vector
isfromtoby <- function(x) {
  (sum(names(x) %in% c("from","to","by"))==3)
}

hasfromtoby <- function(x) {
  any(names(x) %in% c("from","to","by"))
}

## expand from-to-by-vector to sequence
fromtoby <- function(times) {
  if (isfromtoby(times)) {
    times <- seq(times["from"], times["to"], times["by"])
  } 
  times
}
back to top