R 基于特定列表元素筛选列表
我有一个列表,其中包含以下内容:R 基于特定列表元素筛选列表,r,R,我有一个列表,其中包含以下内容: $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 o
$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值
进行过滤。我可以使用:d$AKAM$p.value
访问p-value
。我想根据p值<0.05的标准筛选列表
数据:
dsapply(d,函数(x)x$p.value<0.05)
#ABMD ATVI ADBE AMD AKAM ALXN
#假假假假真假
从列表中筛选数据
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
d[sapply(d,函数(x)x$p.value<0.05]
#$AKAM
#
#扩充Dickey-Fuller检验
#
#数据:Cl(.)
#Dickey Fuller=-3.6785,滞后顺序=3,p值=0.03802
#替代假设:平稳
涉及purr
的一个选项可以是:
discard(d, ~ .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
我们可以从base R
Filter(function(x) x$p.value < 0.05, d)
#$AKAM
# Augmented Dickey-Fuller Test
#data: Cl(.)
#Dickey-Fuller = -3.6785, Lag order = 3, p-value = 0.03802
#alternative hypothesis: stationary
如果我回答了你的问题,请向上投票并接受它。我以前不知道discard
函数,谢谢!谢谢所以keep
与purr
包中的discard
相反吗?两个新功能,谢谢@user113156是的,这是一个基于所用逻辑的方便函数(当然少键入:=nchar)
discard(d, ~ .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
Filter(function(x) x$p.value < 0.05, d)
#$AKAM
# Augmented Dickey-Fuller Test
#data: Cl(.)
#Dickey-Fuller = -3.6785, Lag order = 3, p-value = 0.03802
#alternative hypothesis: stationary
library(purrr)
keep(d, ~ .x$p.value < 0.05)