我试图读入的文件在列标题中有一个"数字符号 - #"(也就是哈希符号).当我使用read.table加载数据时,列被移动,并且哈希符号(或数字符号#)之后的列标题丢失了!
如何将"数字符号"作为列标题的一部分读入,
防爆.标题,作者,标准#,日期,原产国
42-*_*42- 24
read.table有一个参数允许更改注释字符:
read.table( ...., comment.char="", ...) # or suppressed as I show here:
read.table(textConnection("title, author, criterion#, date, country of origin\nA, b, C, 1/1/1939, USA"),
sep=",", comment.char="", header=TRUE)
# title author criterion. date country.of.origin
# 1 A b C 1/1/1939 USA
Run Code Online (Sandbox Code Playgroud)
check.names
如果header = TRUE ,则hash或octothorpe会被函数转换为句点,read.table仅在第1行调用.(即使绝对必要,也可以抑制强制.)这个问题在text="..."
参数scan
和read.table
和read.
-cousins 的到来之前得到了解答,因此textConnection
除非你使用,否则不再需要示例结构readLines
.可以使用read.table(text= ..<und-so-weiter>.. )