[英]R Quantiles of matrix - wrong output
我可能在這里犯了一些簡單的錯誤,但我有一個矩陣,我想產生整個矩陣的分位數。 我試過這個:
quantile(unlist(ricepm), probs = c(.25, .5, .75))
但這給了我錯誤的 output(全為 1)
25% 50% 75%
1 1 1
我的數據的dput(head(ricepm[, c(5, 5)]))
樣本
structure(
list(
Antigua.and.Barbuda =
structure(c(1L, 1L, 1L, 1L, 1L, 24L),
.Label =
c("0", "0,001255087", "0,001351049", "0,002179536",
"0,002322295", "0,00352192", "0,003639649", "0,005203948", "0,005613623",
"0,005899437", "0,0063163", "0,008692968", "0,010768326", "0,01815333",
"0,022817923", "0,05455008", "0,076043772", "0,761972864", "1,167911482",
"11,39171454", "17,55057703", "2,827338354", "3,180646314", "3,18612071",
"3,519189594", "376,5666716", "4,22468796", "5,861801198", "572,3941286",
"76,13680349"
),
class = "factor"
),
Antigua.and.Barbuda.1 =
structure(
c(1L, 1L, 1L, 1L, 1L, 24L),
.Label =
c("0", "0,001255087", "0,001351049",
"0,002179536", "0,002322295", "0,00352192", "0,003639649", "0,005203948",
"0,005613623", "0,005899437", "0,0063163", "0,008692968", "0,010768326",
"0,01815333", "0,022817923", "0,05455008", "0,076043772", "0,761972864",
"1,167911482", "11,39171454", "17,55057703", "2,827338354", "3,180646314",
"3,18612071", "3,519189594", "376,5666716", "4,22468796", "5,861801198",
"572,3941286", "76,13680349"
),
class = "factor"
)
),
row.names =
c("Afghanistan","Albania", "Algeria", "Angola", "Antigua and Barbuda", "Argentina"),
class = "data.frame"
)
如果您只想將矩陣Z
的所有值放入向量中並從中獲取分位數,您可以執行以下操作:
# Put values inside vector
Z_vec = as.vector(Z)
# Compute quantiles
quantile(Z_vec, probs = c(.25, .5, .75))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.