如果我想使用“$”來獲取 dplyr 管道中串列的子元素怎么辦?
問題來自: 我在每種情況下都呼叫了 boxplot.stats()(4 個因素:值、金屬、顛簸、參考):
match.raw %>%
select(-id) %>%
group_by(value, metallic, bumpiness, reference) %>%
group_split() %>%
map(select, diff) %>%
map(as.matrix) %>%
map(boxplot.stats)
然后我得到了多個 boxplot.stats 呼叫的一堆結果。我想從每個 boxplot.stats 結果中獲取“輸出”資訊,就像:
boxplot.stats(x)$out
這是我的資料:
> head(match.raw, 20)
id value metallic bumpiness reference match diff
1 1 1.0 1.0 0.5 0.7 0.74 0.04
2 1 1.0 1.0 0.5 0.9 0.88 -0.02
3 1 1.0 0.0 0.5 0.3 0.30 0.00
4 1 0.0 0.5 0.5 0.3 0.32 0.02
5 1 1.0 0.0 0.5 0.7 0.46 -0.24
6 1 0.0 1.0 0.5 0.3 0.28 -0.02
7 1 0.0 1.0 0.5 0.7 0.72 0.02
8 1 1.0 0.5 0.5 0.5 0.56 0.06
9 1 0.5 0.0 0.5 0.9 0.84 -0.06
10 1 0.0 0.5 0.5 0.5 0.54 0.04
11 1 0.5 1.0 0.5 0.1 0.10 0.00
12 1 0.5 0.5 0.5 0.9 0.96 0.06
13 1 1.0 0.0 0.5 0.1 0.00 -0.10
14 1 0.0 0.5 0.5 0.9 0.92 0.02
15 1 1.0 0.5 0.5 0.9 0.94 0.04
16 1 1.0 0.5 0.5 0.1 0.28 0.18
17 1 1.0 1.0 0.5 0.1 0.10 0.00
18 1 0.0 0.5 0.5 0.1 0.22 0.12
19 1 1.0 0.0 0.5 0.5 0.00 -0.50
20 1 0.5 0.5 0.5 0.7 0.78 0.08
uj5u.com熱心網友回復:
試試這個。
library(purrr); library(dplyr)
match.raw %>%
select(-id) %>%
group_by(value, metallic, bumpiness, reference) %>%
group_split() %>%
map(select, diff) %>%
map(as.matrix) %>%
map(boxplot.stats) %>%
map(\(.) .$out) %>%
unlist()
不過,您的示例資料無處不numeric(0)在"out"。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/397035.html
