gpt4 book ai didi

r - 基于特定列表元素过滤列表

转载 作者:行者123 更新时间:2023-12-03 21:58:08 27 4
gpt4 key购买 nike

我有一个包含以下内容的列表:

$AKAM

Augmented Dickey-Fuller Test

data: Cl(.)
Dickey-Fuller = -3.6785, Lag order = 3, p-value = 0.03802
alternative hypothesis: stationary


$ALXN

Augmented Dickey-Fuller Test

data: Cl(.)
Dickey-Fuller = -2.9311, Lag order = 3, p-value = 0.2052
alternative hypothesis: stationary

我想根据 p-value 过滤.我可以访问 p-value使用: d$AKAM$p.value .我想根据 p 值 < 0.05 的标准过滤列表。

数据:
d <- list(ABMD = structure(list(statistic = c(`Dickey-Fuller` = -2.88823930907752), 
parameter = c(`Lag order` = 3), alternative = "stationary",
p.value = 0.222153876057991, method = "Augmented Dickey-Fuller Test",
data.name = "Cl(.)"), class = "htest"), ATVI = structure(list(
statistic = c(`Dickey-Fuller` = -2.86560166108736), parameter = c(`Lag order` = 3),
alternative = "stationary", p.value = 0.231115731952747,
method = "Augmented Dickey-Fuller Test", data.name = "Cl(.)"), class = "htest"),
ADBE = structure(list(statistic = c(`Dickey-Fuller` = -2.91292875187715),
parameter = c(`Lag order` = 3), alternative = "stationary",
p.value = 0.212379749850693, method = "Augmented Dickey-Fuller Test",
data.name = "Cl(.)"), class = "htest"), AMD = structure(list(
statistic = c(`Dickey-Fuller` = -3.46654255102478), parameter = c(`Lag order` = 3),
alternative = "stationary", p.value = 0.0592779965240372,
method = "Augmented Dickey-Fuller Test", data.name = "Cl(.)"), class = "htest"),
AKAM = structure(list(statistic = c(`Dickey-Fuller` = -3.67846516682619),
parameter = c(`Lag order` = 3), alternative = "stationary",
p.value = 0.0380202892654308, method = "Augmented Dickey-Fuller Test",
data.name = "Cl(.)"), class = "htest"), ALXN = structure(list(
statistic = c(`Dickey-Fuller` = -2.93110833009175), parameter = c(`Lag order` = 3),
alternative = "stationary", p.value = 0.205182767184581,
method = "Augmented Dickey-Fuller Test", data.name = "Cl(.)"), class = "htest"))

最佳答案

sapply(d, function(x) x$p.value < 0.05)
# ABMD ATVI ADBE AMD AKAM ALXN
# FALSE FALSE FALSE FALSE TRUE FALSE

从列表中过滤数据
d[sapply(d, function(x) x$p.value < 0.05)]
# $AKAM
#
# Augmented Dickey-Fuller Test
#
# data: Cl(.)
# Dickey-Fuller = -3.6785, Lag order = 3, p-value = 0.03802
# alternative hypothesis: stationary

关于r - 基于特定列表元素过滤列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61086513/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com