Learn R Programming

docxtractr (version 0.6.5)

assign_colnames: 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 data.frame but is intended for use with ones retuned by this package

row

numeric value indicating the row number that is to become the column names

remove

remove row specified by row after making it the column names? (Default: TRUE)

remove_previous

remove any rows preceding row? (Default: TRUE but will be assigned whatever is given for remove).

Value

data.frame

See Also

docx_extract_all, docx_extract_tbl

Examples

Run this code
# NOT RUN {
# 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)
# }

Run the code above in your browser using DataLab