I have multiple tables loaded using lapply. The last colname is not the same for all tables which makes it impossible to rbind the tables. I would like to make a new column that contains the colname in column 10 as ID, then rename the colname of column 10 to X.
file_list <- list.files(pattern = "edit")
tables <- lapply(file_list, read.csv, header = T, sep="\t")
colnames(tables[[984]])
[1] "X.CHROM" "POS" "ID"
[4] "REF" "ALT" "QUAL"
[7] "FILTER" "INFO" "FORMAT"
[10] "ID02020886"
My try:
tables <- map2(tables, file_list, ~cbind(.x, ID = .y)) #Does not work....
Desired out:
colnames(tables[[984]])
[1] "X.CHROM" "POS" "ID"
[4] "REF" "ALT" "QUAL"
[7] "FILTER" "INFO" "FORMAT"
[10] "X" "ID"