use first row data as column names in r

后端 未结 8 1589
遇见更好的自我
遇见更好的自我 2020-12-05 09:58

I have a dirty dataset that I could not read it with header = T. After I read and clean it, I would like to use the now first row data as the column name. I tri

8条回答
  •  有刺的猬
    2020-12-05 10:37

    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)
    

提交回复
热议问题