Elevate a row to be the column names of a data.frame.
Arguments
- dat
The input data.frame
- row_number
The row(s) of
datcontaining the variable names or the string"find_header"to usefind_header(dat=dat, ...)to find the row_number. Allows for multiple rows input as a numeric vector. NA's are ignored, and if a column contains onlyNAvalue it will be named"NA".- ...
Sent to
find_header(), ifrow_number = "find_header". Otherwise, ignored.- remove_row
Should the row
row_numberbe removed from the resulting data.frame?- remove_rows_above
If
row_number != 1, should the rows aboverow_number- that is, between1:(row_number-1)- be removed from the resulting data.frame?- sep
A character string to separate the values in the case of multiple rows input to
row_number.
See also
Other Set names:
clean_names(),
find_header(),
mu_to_u
Examples
x <- data.frame(
X_1 = c(NA, "Title", 1:3),
X_2 = c(NA, "Title2", 4:6)
)
x %>%
row_to_names(row_number = 2)
#> Title Title2
#> 3 1 4
#> 4 2 5
#> 5 3 6
x %>%
row_to_names(row_number = "find_header")
#> Title Title2
#> 3 1 4
#> 4 2 5
#> 5 3 6