我正在将数据帧编写为.bed文件;数据帧看起来很好,但当我使用以下命令导出它时:
write.table(x = bed_file,
file = 'merged_out.bed',
row.names = F,
col.names = F,
quote = F,
sep = '\t')然后在终端中查看merged.bed的标题,有些行是空格分隔的,但大多数是制表符分隔的。。。有什么想法吗?
chr1 3816670 3818113 181 4
chr1 6452977 6454435 181 1
chr1 8075042 8075406 181 5
chr1 8389451 8389713 181 1
chr1 11190170 11190527 181 1
chr1 14454661 14454861 181 2
chr1 16212079 16213143 181 2 发布于 2020-09-06 02:41:35
我怀疑这些不是“空格”,而只是空格,实际上是制表符。
要验证:
### the first row
readLines("merged_out.bed", n = 1)
# [1] "chr1\t3816670\t3818113\t181\t4"
### the first seemingly-wrong line
readLines("merged_out.bed", skip = 4, n = 1)
# [1] "chr1\t3816670\t3818113\t181\t4"很明显,这两行中没有" "字符。
如果您想查看文件中是否有任何文字空格,此表达式将验证整个文件(假设字段中没有合法空格):
any(grepl(" ", readLines("merged_out.bed")))
# [1] FALSE数据准备:
dat <- read.table(text = "
chr1 3816670 3818113 181 4
chr1 6452977 6454435 181 1
chr1 8075042 8075406 181 5
chr1 8389451 8389713 181 1
chr1 11190170 11190527 181 1
chr1 14454661 14454861 181 2
chr1 16212079 16213143 181 2 ")
write.table(dat, "merged_out.bed",
row.names = FALSE, col.names = FALSE, quote = FALSE, sep = "\t")https://stackoverflow.com/questions/63756494
复制相似问题