r - 忽略文本文件标题中的#(R语言)

标签 r input header read.table

我在 R 中使用 read.table 读取具有以下 header 的文件:

ColA ColB# ColC ColD ColE

但是,在 header 名称中包含“#”会混淆 read.table,我会收到以下错误:

*Error in read.table(paste(path, file, sep = ""), skip = SKIP_LINES, sep = "", : more columns than column names*

有什么建议可以消除错误消息吗?

最佳答案

为了改进 BrodieG 的回答,以防万一文件中有随机问号(“?”),当您想忽略任何和所有注释字符时,使用 comment.char=""是正确的约定。

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 - 忽略文本文件标题中的#(R语言),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20913064/

相关文章:

c++ - 接收输入的无等待命令

c# - 使用 HttpRequestMessageProperty 和 OperationContextScope 的 WCF HTTP header

printing - Swift 2 中的 WKWebView 打印响应 header

c++ - 为什么我们需要为每个类函数定义指定类型模板参数?

r - 使用 R markdown 和 knitr : Possible to get R objects interpreted in YAML

java - 如何根据用户输入执行不同的操作

r - 如何复制数据框中的列

javascript - 为什么 setCustomValidity ('' ) 在输入时被忽略 (Chrome 65)

r - 将大量的 tibble 转换为单个 tibble

r - dplyr 0.3.0.2 rename() 习惯用法在加载 reshape 包时不稳定