简体   繁体   中英

R write.table with different delimiters

I would like to save a file with 11 columns. All columns but two have to be separated by a tab and the remaining one by white space (please do not ask me, what sort of programmer came up with this idea, it was not my idea!).

m <- data.frame("DIN156", 6, 1, 255, "DINs", "_00:01:00.000000", "_00:00:00.001", "gidx", 1, "cidx", 1)

The 4th and 5th column have to be separated by white space, the rest by tabs.

Any idea how to do this? Thanks!

m <- data.frame("DIN156", 6, 1, 255, "DINs", "_00:01:00.000000", "_00:00:00.001", "gidx", 1, "cidx", 1)
m[, 4] <- paste(m[, 4], m[, 5])
colnames(m)[4] <- paste(colnames(m)[4:5], collapse = " ")
m[, 5] <- NULL
write.table(m, file = "myfile.txt", sep = "\t")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM