![](/img/trans.png)
[英]how to subset data frame to contain all elements that contain a certain word
[英]how to subset a list where certain column does not contain
$DANN_score
label Predictor label
79 0 DANN_score 0.999
80 0 DANN_score .
81 0 DANN_score 0.934
82 0 DANN_score 0.543
83 0 DANN_score .
84 0 DANN_score .
$fathmm.MKL_coding_score
label Predictor label
85 0 fathmm.MKL_coding_score 0.977
86 0 fathmm.MKL_coding_score .
87 0 fathmm.MKL_coding_score 0.147
88 0 fathmm.MKL_coding_score 0.089
89 0 fathmm.MKL_coding_score .
90 0 fathmm.MKL_coding_score .
我想删除label
='。'的元素 即丢失数据。
我只知道如何使用数据框(我不想将其转换为)执行此操作,例如
subset(df,df[3] != '.')
那么我该如何使用列表呢?
我们可以使用lapply
遍历list
,并基于第三列对行进行子集化
lapply(lst, function(x) x[x[[3]]!=".",])
#$DANN_score
# label Predictor label
#79 0 DANN_score 0.999
#81 0 DANN_score 0.934
#82 0 DANN_score 0.543
#$fathmm.MKL_coding_score
# label Predictor label
#85 0 fathmm.MKL_coding_score 0.977
#87 0 fathmm.MKL_coding_score 0.147
#88 0 fathmm.MKL_coding_score 0.089
lst <- structure(list(DANN_score = structure(list(label = c(0L, 0L,
0L, 0L, 0L, 0L), Predictor = c("DANN_score", "DANN_score", "DANN_score",
"DANN_score", "DANN_score", "DANN_score"), label = c("0.999",
".", "0.934", "0.543", ".", ".")), .Names = c("label", "Predictor",
"label"), class = "data.frame", row.names = c("79", "80", "81",
"82", "83", "84")), fathmm.MKL_coding_score = structure(list(
label = c(0L, 0L, 0L, 0L, 0L, 0L), Predictor = c("fathmm.MKL_coding_score",
"fathmm.MKL_coding_score", "fathmm.MKL_coding_score", "fathmm.MKL_coding_score",
"fathmm.MKL_coding_score", "fathmm.MKL_coding_score"), label = c("0.977",
".", "0.147", "0.089", ".", ".")), .Names = c("label", "Predictor",
"label"), class = "data.frame", row.names = c("85", "86", "87",
"88", "89", "90"))), .Names = c("DANN_score", "fathmm.MKL_coding_score"
))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.