assign_colnames {docxtractr} | R Documentation |
Make a specific row the column names for the specified data.frame
Description
Many tables in Word documents are in twisted formats where there may be
labels or other oddities mixed in that make it difficult to work with the
underlying data. This function makes it easy to identify a particular row
in a scraped data.frame
as the one containing column names and
have it become the column names, removing it and (optionally) all of the
rows before it (since that's usually what needs to be done).
Usage
assign_colnames(dat, row, remove = TRUE, remove_previous = remove)
Arguments
dat |
can be any |
row |
numeric value indicating the row number that is to become the column names |
remove |
remove row specified by |
remove_previous |
remove any rows preceding |
Value
data.frame
See Also
docx_extract_all
, docx_extract_tbl
Examples
# a "real" Word doc
real_world <- read_docx(system.file("examples/realworld.docx", package="docxtractr"))
docx_tbl_count(real_world)
# get all the tables
tbls <- docx_extract_all_tbls(real_world)
# make table 1 better
assign_colnames(tbls[[1]], 2)
# make table 5 better
assign_colnames(tbls[[5]], 2)