View source: R/row-to-colnames.R
row_to_colnames | R Documentation |
Data frames sometimes have wrong column names, while the correct
column names are stored in one or more rows in the data frame itself. To
remedy this issue, call row_to_colnames()
on the data frame: It replaces
the column names by the values of the specified rows (by default, only the
first one). These rows are then dropped by default.
row_to_colnames(data, row = 1L, collapse = " ", drop = TRUE)
data |
Data frame or matrix. |
row |
Integer. Position of the rows (one or more) that jointly contain
the correct column names. Default is |
collapse |
String. If the length of |
drop |
Logical. If |
If multiple rows are specified, the row values for each individual column are pasted together. Some special characters might then be missing.
This function might be useful when importing tables from PDF, e.g. with tabulizer. In R, these data frames (converted from matrices) do sometimes have the issue described above.
A tibble (data frame).
unheadr::mash_colnames()
, a more sophisticated solution to the
same problem.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.