如何将“starts_with”嵌入到我的字段列表中的数据框子集?这是我到目前为止的尝试。该错误要求将其与选择功能一起使用,尽管我认为我正在这样做?谢谢!
df <- subset(raw_df, select=c(col1, col2, col3, V1, V2, starts_with("V")))
答案 0 :(得分:1)
starts_with
是来自 tidyselect
包的选择助手。我们可能需要来自 startsWith
base R
subset(raw_df, select=c(col1, col2, col3,
names(raw_df)[startsWith(names(raw_df), "V")]))
这在 dplyr
中也可能更紧凑
library(dplyr)
raw_df %>%
select(matches('^col[1-3]$'), starts_with("V"))