find_header {janitor} | R Documentation |
Find the header row in a data.frame
Description
Find the header row in a data.frame
Usage
find_header(dat, ...)
Arguments
dat |
The input data.frame |
... |
See details |
Details
If ...
is missing, then the first row with no missing values is used.
When searching for a specified value or value within a column, the first row
with a match will be returned, regardless of the completeness of the rest of
that row. If ...
has a single character argument, then the first
column is searched for that value. If ...
has a named numeric
argument, then the column whose position number matches the value of that
argument is searched for the name (see the last example below). If more than one
row is found matching a value that is searched for, the number of the first
matching row will be returned (with a warning).
Value
The row number for the header row
See Also
Other Set names:
clean_names()
,
mu_to_u
,
row_to_names()
Examples
# the first row
find_header(data.frame(A="B"))
# the second row
find_header(data.frame(A=c(NA, "B")))
# the second row since the first has an empty value
find_header(data.frame(A=c(NA, "B"), B=c("C", "D")))
# The third row because the second column was searched for the text "E"
find_header(data.frame(A=c(NA, "B", "C", "D"), B=c("C", "D", "E", "F")), "E"=2)