When I write a table in R, the rownames are printed as first column. However, the first column name (from the object) is automatically placed above the rownames, like this:
Object Output table:
Sample1 Sample2 Sample3 Sample1 Sample2 Sample3:
Gene1 4 32 5 Gene1 4 32 5
Gene2 23 43 23 Gene2 3 43 23
Gene3 24 34 14 Gene3 4 34 14
I tried different ways to solve this, e.g.:
names <- c("GeneNr", names(DF))
names
# [1] "GeneNr" "Sample1" "Sample2" "Sample3"
write.table(DF, file= "DF.txt"), sep = "\t", col.names = names)
but this does not work.
Does any know how to solve this?
The simultaneous use of row.names=T and col.names=NA permits to correctly place your column names.
write.table(df, "df.txt", sep = "\t", row.names = T, quote = F, col.names = NA)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With