gpt4 book ai didi

r - 如何从大量数据中搜索和检索特定列

转载 作者:行者123 更新时间:2023-12-02 06:51:04 24 4
gpt4 key购买 nike

我有一个数据看起来像这样

df<- structure(list(X..taminn = c(86L, 102L, 34L, 35L, 53L, 54L, 43L, 
31L, 62L, 54L), X..turtia = c(413L, 322L, 525L, 535L, 247L, 207L,
241L, 440L, 189L, 221L), X..bestt = c(82L, 102L, 6L, 2L, 46L,
1L, 39L, 7L, 62L, 54L), Best..F1..129..test = c(3079.3, 1512.9,
497, 2804.5, 1353.7, 1597.6, 2005.1, 186.4, 1847.5, 1558.2),
best..F1..130..test = c(8972.7, 1944, 2022.7, 13001.7, 2085,
3228.6, 4948.5, 943.6, 1329, 2655.9), best..F1..131..test = c(2634.4,
1181.3, 505.2, 2802.4, 1573.2, 1707.6, 1585.9, 192.1, 809.2,
1219), how1 = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
2L, 1L), .Label = c("", "High", "Not Found"), class = "factor"),
how2 = structure(c(2L, 2L, 2L, 3L, 2L, 2L, 2L, 3L, 2L, 1L
), .Label = c("", "High", "Not Found"), class = "factor"),
how3 = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L
), .Label = c("", "High"), class = "factor"), Best.test...F1..129..test = c(3079.3,
1512.9, 497, 2804.5, 1353.7, 1597.6, 2005.1, 186.4, 1847.5,
1558.2), best.test...F1..130..test = c(8972.7, 1944, 2022.7,
13001.7, 2085, 3228.6, 4948.5, 943.6, 1329, 2655.9), best.test...F1..131..test = c(2634.4,
1181.3, 505.2, 2802.4, 1573.2, 1707.6, 1585.9, 192.1, 809.2,
1219), Best..test..129..test = c(3079.3, 1512.9, 497, 2804.5,
1353.7, 1597.6, 2005.1, 186.4, 1847.5, 1558.2), best..test..130..test = c(8972.7,
1944, 2022.7, 13001.7, 2085, 3228.6, 4948.5, 943.6, 1329,
2655.9), best..test..131..test = c(2634.4, 1181.3, 505.2,
2802.4, 1573.2, 1707.6, 1585.9, 192.1, 809.2, 1219)), .Names = c("X..taminn",
"X..turtia", "X..bestt", "Best..F1..129..test", "best..F1..130..test",
"best..F1..131..test", "how1", "how2", "how3", "Best.test...F1..129..test",
"best.test...F1..130..test", "best.test...F1..131..test", "Best..test..129..test",
"best..test..130..test", "best..test..131..test"), class = "data.frame", row.names = c(NA,
-10L))

基本上,我想提取所有名称以

开头的列
best..F1   
best..F2
.
.

有没有一种方法可以做到这一点而无需一个一个地访问数据并找到它的位置?

最佳答案

你可以像这样尝试 grep:

df[,grep("^best\\.\\.F",names(df))]

关于r - 如何从大量数据中搜索和检索特定列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44418843/

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