Sam Firke's ever useful package janitor
has a function especially for this: row_to_names
.
Example from his documentation:
library(janitor)
x <- data.frame(X_1 = c(NA, "Title", 1:3),
X_2 = c(NA, "Title2", 4:6))
x %>%
row_to_names(row_number = 2)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…