如果标签名称在 R 编程中以 "G" 开头,如何删除列标签

How to remove column labels if the name of the label starts with "G" in R programming

如果标签名称以“G”开头,如何删除列标签

代码:

library(pdftools)
library(data.table)
library(tabulizer)
pdf_file <- "new.pdf"

out2 <- extract_tables(pdf_file, pages =c(89), output = "data.frame")
out2<-as.data.table(out2)
colnames(out2)

实际输出:

"Group.1" "Day.7"   "Day.8" "Day.9"
"Group.2" "Day.10" "Day.11", "Day.12"

预期输出:

"Day.7"   "Day.8" "Day.9"
"Day.10" "Day.11", "Day.12"

另外,请向我推荐任何其他从 PDF 中提取数据表的 R 包(pdftools 和 tabulizer 除外)

这将删除以 "G":

开头的列
result <- out2[, !startsWith(names(out2), "G")]

您可以使用 dplyr::select:

library(dplyr)

dplyr::select(out2, -starts_with("G"))