R/utils.R

Defines functions asInteger invDiag nameToString rmAttr Rnumber Rname closest locf colClasses nDistinct interleave

Documented in asInteger closest colClasses interleave invDiag locf nameToString nDistinct rmAttr Rname Rnumber

asInteger <- function(x)
    as.integer(round(x))

invDiag <- function(x) {
    vec <- integer(x ^ 2)
    vec[cumsum(rep(x - 1, x)) + 1] <- 1
    matrix(vec, nrow = x)
}

"%out%" <- function(x, y)
    ! x %in% y

nameToString <- function(x)
    deparse(substitute(x))

rmAttr <- function(x, except = "class") {
    nAttr <- names(attributes(x))
    attributes(x) <- attributes(x)[except]
    x
}

Rnumber <- function()
    paste((v <- R.Version())$major, v$minor, sep = ".")

Rname <- function()
    R.Version()$nickname

closest <- function(x, y, tol = +Inf)
    (d <- abs(x - y)) == min(d) & (d < tol)

locf <- function(x)
    (x2 <- na.omit(x))[length(x2)]

colClasses <- function(x)
    unlist(lapply(lapply(x, class), function(x) x[length(x)]))

nDistinct <- function(x)
    length(table(x))

interleave <- function(x, y) {
  iX <- 2 * seq_along(x) - 1
  iY <- 2 * seq_along(y)
  c(x, y)[order(c(iX, iY))]
}

Try the rmngb package in your browser

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

rmngb documentation built on May 29, 2017, 9:22 p.m.