开发者

How can read 'Numeral Signs-#' as part of a column header?

The file I am trying to read in has a 'numeral sign-#' (aka hash symbol) in the column header. 开发者_如何学Go When I used read.table to load the data the columns were shifted and the column headers AFTER the hash symbol (or numeral sign-#) were missing!

How do I read in 'numeral signs' as part of my column headers,

Ex. title, author, criterion#, date, country of origin


There is an argument to read.table that allows the comment character be changed:

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

The hash or octothorpe gets turned into a period by the check.names function which read.table calls only on line 1 if header=TRUE. (And even that coercion can be suppressed if absolutely necessary.) This question was answered before the arrival of the text="..." parameter for scan and read.table and read.-cousins, so textConnection is no longer needed for example constructions unless you use readLines. Can use read.table(text= ..<und-so-weiter>.. )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜