View source: R/row_to_names_fill.R
| row_to_names_fill | R Documentation |
Casts data from rows to the column names of a data frame, with the option to fill
missing values row-wise. This utility is helpful in the case of merged cells in
Microsoft Excel, where the merged range has data only in the first (unmerged) cell.
This function is similar to janitor::row_to_names(), with the exception of
the fill utility.
row_to_names_fill(
data,
row_number,
fill_missing = TRUE,
remove_row = TRUE,
remove_rows_above = TRUE,
sep = "_"
)
data |
A data frame. |
row_number |
A numeric vector with he row indices of |
fill_missing |
A logical vector of length 1 or of length |
remove_row |
A logical vector of length 1, denoting if the row |
remove_rows_above |
A logical vector of length 1, denoting if the rows above
|
sep |
A character vector of length 1 to separate the values in the case of
multiple rows input to |
A data frame (class data.frame) with the same structure as the input data,
but with column names derived from the specified row(s). The returned data frame
has the same number of columns as the input, with rows removed according to the
remove_row and remove_rows_above parameters. All data types and values are
preserved from the original data frame.
df <- data.frame(
a = 1:6,
b = rep(c("x", NA), 3),
c = letters[1:6]
)
df
row_to_names_fill(df, 2:3)
row_to_names_fill(df, 2:3, sep = ".")
row_to_names_fill(df, 2:4, fill_missing = c(TRUE, FALSE, FALSE))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.