0

I'm trying to load a csv file that has symbol '#' in the header. This is causing an error message 'More Columns than Column Names'. I've followed some the articles (here & here), but I can not manage to sort it out.

The problem seems to be that the upload excludes columns after the #. For example, I've created a file with the following column headers (no rows)

A   B#  C # D

When I upload I get the following:

hTest <- read.table("C:/Users/xxx/headerTest.csv",header=T, sep = ',',check.names=FALSE)
hTest
[1] A B
<0 rows> (or 0-length row.names)

As you can see, after the # in column B the following columns are ignored

Any ideas on how to resolve the problem?

Thanks

Community
  • 1
  • 1
Selrac
  • 2,203
  • 9
  • 41
  • 84
  • Have you tried treating column names as 1st row? doing header = F, and col classes all as character? – M. Siwik Feb 06 '17 at 10:59

1 Answers1

1

Try comment.char = ''

df1 <- read.table("temp.txt", header = TRUE, sep = "\t", comment.char = '')

You will get a . in place of #. After reading the file contents, you can edit the column names using colnames() function.

Sathish
  • 12,453
  • 3
  • 41
  • 59