R/as.yearmon2.R

Defines functions as.yearmon2

Documented in as.yearmon2

as.yearmon2 <- function(x, ...){
  clx <- class(x)
  {
    if((length(clx)==1) && (clx=="numeric") && (round(x, 2) == x)){
      ix <- format(x, nsmall=2)
      ox <- as.yearmon(ix, "%Y.%m")
      names(ox) <- ix 
    }
    else{
      ox <- as.yearmon(x, ...)
      names(ox) <- x
    }
  }
  if((nox <- length(unique(ox))) != (nx <- length(x))){
    warning(nx-nox, " duplicate months found in 'x'; ",
            " returning 'x' unchanged")
    return(x)
  }
  ox 
}

Try the FinTS package in your browser

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

FinTS documentation built on Jan. 27, 2024, 3:01 a.m.