The file I am trying to read in has a 'numeral sign-#' (aka hash symbol) in the column header. 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>.. )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With