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


R modelr typical 求典型值

對於數字、整數和有序因子向量,它返回中值。對於因子、字符和邏輯向量,它返回最常見的值。如果多個值與最常見的值相關,則返回全部值。 NA 缺失值總是默默地被刪除。

用法

typical(x, ...)

參數

x

一個向量

...

方法使用的參數

例子

# median of numeric vector
typical(rpois(100, lambda = 10))
#> [1] 9

# most frequent value of character or factor
x <- sample(c("a", "b", "c"), 100, prob = c(0.6, 0.2, 0.2), replace = TRUE)
typical(x)
#> [1] "a"
typical(factor(x))
#> [1] "a"

# if tied, returns them all
x <- c("a", "a", "b", "b", "c")
typical(x)
#> [1] "a" "b"

# median of an ordered factor
typical(ordered(c("a", "a", "b", "c", "d")))
#> [1] "b"

源代碼:R/typical.R

相關用法


注:本文由純淨天空篩選整理自Hadley Wickham等大神的英文原創作品 Find the typical value。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。