R/index2char.R

Defines functions index2char.numeric index2char.POSIXt index2char.default index2char

Documented in index2char index2char.default index2char.numeric index2char.POSIXt

index2char <- function(x, ...) UseMethod("index2char")

index2char.default <- function(x, ...) as.character(x)

index2char.POSIXt <- function(x, ...) format(x, ...)

index2char.numeric <- function(x, frequency = NULL, digits = getOption("digits") - 3, ...)
{
  freq <- frequency
  if(is.null(freq)) return(as.character(round(x, digits = digits)))
  if(length(x) < 1) return(character(0))
  d <- diff(x)
  if(freq > 1 && identical(all.equal(freq, round(freq)), TRUE)) freq <- round(freq)
  if(identical(all.equal(freq*d, round(freq*d)), TRUE)) {
    if(freq == 1) return(as.character(round(x)))
      else return(paste(floor(x), "(", round((x - floor(x)) * freq) + 1, ")", sep = ""))
  } else
    return(as.character(round(x, digits = digits)))
}

Try the zoo package in your browser

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

zoo documentation built on April 14, 2023, 12:39 a.m.