use first row data as column names in r

后端 未结 8 1623
遇见更好的自我
遇见更好的自我 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条回答
  •  旧时难觅i
    2020-12-05 10:31

    While @sbha has already offered a tidyverse solution, I would like to leave a fully pipeable dplyr option. I agree that this should could be an incredibly useful function.

    library(dplyr)
    data.frame(x = c("a", 1, 2, 3), y = c("b", 4, 5, 6)) %>%
      `colnames<-`(.[1, ]) %>%
      .[-1, ]
    

提交回复
热议问题