是否可以在 R 中指定由 1 个以上符号组成的注释字符?
例如,
read.table("data.dat", comment.char="//")
行不通。
最佳答案
我认为你不能,但这里有一个解决方法。读取文件的函数,使用 sub
清理其行,并在将其传递给 read.table
之前将所有内容粘贴回一起:
my.read.table <- function(file, comment.char = "//", ...) {
clean.lines <- sub(paste0(comment.char, ".*"), "", readLines(file))
read.table(..., text = paste(clean.lines, collapse = "\n"))
}
测试:
file <- textConnection("3 4 //a
1 2")
my.read.table(file)
# V1 V2
# 1 3 4
# 2 1 2
关于r - 在 R 的 read.table() 中指定多字符注释标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15513956/