⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 na.roughfix.r

📁 是基于linux系统的C++程序
💻 R
字号:
na.roughfix <- function(object, ...)  UseMethod("na.roughfix")na.roughfix.data.frame <- function(object, ...) {##  n <- length(object)##  vars <- seq(length = n)  isfac <- sapply(object, is.factor)  isnum <- sapply(object, is.numeric)  hasNA <- which(sapply(object, function(x) any(is.na(x))))  if (any(!(isfac | isnum)))      stop("na.roughfix only works for numeric or factor")  for (j in hasNA) {    if (isfac[j]) {      freq <- table(object[[j]])      xmode <- names(freq)[max.col(rbind(freq))]      object[[j]][is.na(object[[j]])] <- xmode    } else {      xmed <- median(object[[j]], na.rm=TRUE)      object[[j]][is.na(object[[j]])] <- xmed    }  }  object}na.roughfix.default <- function(object, ...) {  if (!is.atomic(object))     return(object)  d <- dim(object)  if (length(d) > 2)     stop("can't handle objects with more than two dimensions")  if (all(!is.na(object)))    return(object)  if (!is.numeric(object))    stop("roughfix can only deal with numeric data.")  if (length(d) == 2) {      hasNA <- which(apply(object, 2, function(x) any(is.na(x))))      for (j in hasNA)           object[is.na(object[, j]), j] <- median(object[, j], na.rm=TRUE)  } else {      object[is.na(object)] <- median(object, na.rm=TRUE)  }  object}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -