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
header = T
Using data.table:
library(data.table) namex <-c("col1","col2","col3","col4") row1 <- c(2, 4, 5, 56) row2 <- c(74, 73, 3, 534) row3 <- c(865, 768, 8, 7) row4 <- c(68, 58, 65, 87) t1 <- data.table(namex, row1, row2, row3, row4) t1 <- data.table(t(t1)) setnames(t1, as.character(t1[1,])) t1 <- t1[-1,]