row_to_colnames {scrutiny} | R Documentation |
Turn row values into column names
Description
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.
Usage
row_to_colnames(data, row = 1L, collapse = " ", drop = TRUE)
Arguments
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 |
Details
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.
Value
A tibble (data frame).
See Also
unheadr::mash_colnames()
, a more sophisticated solution to the
same problem.