忽略文本文件头中的#(R语言) [英] Ignore # in header in text file (R language)
本文介绍了忽略文本文件头中的#(R语言)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在R中使用read.table来读取具有以下标头的文件:
I am using read.table in R to read in a file which has the following header:
ColA ColB# ColC ColD ColE
但是,标题名称中带有'#'会使read.table混乱,并且出现以下错误:
However, having a '#' in the header name confuses read.table and I get the following error:
* read.table(粘贴(路径,文件,sep ="),skip = SKIP_LINES,sep =",错误:列数多于列名*
*Error in read.table(paste(path, file, sep = ""), skip = SKIP_LINES, sep = "", : more columns than column names*
关于如何消除错误消息的任何建议?
Any suggestions how I can get rid of the error message?
推荐答案
尝试 read.table(comment.char =?" ...)
用作注释.char的位置桌子上没有的东西:
try read.table(comment.char="?" ...)
where what you use as a comment.char is something that isn't in your table:
read.table(
comment.char="?", header=T, check.names=F,
text="ColA ColB# ColC ColD ColE\n1 2 3 4 5"
)
# ColA ColB# ColC ColD ColE
# 1 1 2 3 4 5
这篇关于忽略文本文件头中的#(R语言)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文