当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R class.ind 从因子生成类别指标矩阵


R语言 class.ind 位于 nnet 包(package)。

说明

根据给定因子生成类别指示函数。

用法

class.ind(cl)

参数

cl

案例类的因子或向量。

一个矩阵,除了与该类对应的列之外,其余均为零。

例子

# The function is currently defined as
class.ind <- function(cl)
{
  n <- length(cl)
  cl <- as.factor(cl)
  x <- matrix(0, n, length(levels(cl)) )
  x[(1:n) + n*(unclass(cl)-1)] <- 1
  dimnames(x) <- list(names(cl), levels(cl))
  x
}

参考

Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.

相关用法


注:本文由纯净天空筛选整理自R-devel大神的英文原创作品 Generates Class Indicator Matrix from a Factor。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。