Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

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

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

code:

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)

Actual output:

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

Expected Output:

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

Also Please please suggest to me any other R packages(other than pdftools and tabulizer) that extract Datatables from PDF

question from:https://stackoverflow.com/questions/65847705/how-to-remove-column-labels-if-the-name-of-the-label-starts-with-g-in-r-progra

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This will drop columns that start with "G":

result <- out2[, !startsWith(names(out2), "G")]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...