當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。