1

I have a similar issue to this past question: How can read 'Numeral Signs-#' as part of a column header?

I too have a pound/hash/number sign as part of the name of the first variable in a csv file: "Seg#"

When I read in the csv using readr's "read_csv", I see a warning message about parsing failures, where it says: expected 25 columns, actual 26 columns. It reads in the data, but each column name is shifted to the right, and the first column of data (what was previously under the variable "Seg#") is now missing.

Using read.csv produces the same data frame but without any warnings.

I attempted to solve this using the recommendation in the question linked above:

d1 <- read.csv('11104.wav.csv', comment.char = "", header=T, check.names = FALSE)

...But it simply did the same thing: deleted the first column of data and shifted all names once to the right.

When I attempt "read.table" instead of read.csv, I see the following error message:

Error in read.table("11104.wav.csv", comment.char = "", header = T, check.names = FALSE) : more columns than column names

Any help would be deeply appreciated!


EDIT: Including data example

Here is how the data look in Excel:

Seg#     Start Pos (Sec.)    End Pos (Sec.)  Energy
1   4.96    5.98    2
2   5.98    6.98    4
3   6.98    7.98    5
4   7.98    8.68    8
5   12.02   13.04   3
6   13.04   14.04   2
7   14.04   14.76   3

When read into R, however, the data looks like this:

Seg#    Start Pos (Sec.)    Pos (Sec.)  Energy
4.96    5.98    2   NA
5.98    6.98    4   NA
6.98    7.98    5   NA
7.98    8.68    8   NA
12.02   13.04   3   NA
13.04   14.04   2   NA
14.04   14.76   3   NA
Community
  • 1
  • 1
  • 1
    Can you please include data and/or code that will provide us with a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) ? – Ben Bolker Dec 21 '16 at 19:04
  • What does the column name look like? Is it possible to open the csv with a text editor and just take out the symbol? – Travis Heeter Dec 21 '16 at 19:09
  • Hi Ben, added some data - is this what you mean? – Lizbeth Kennington Dec 21 '16 at 19:10
  • Hi Travis - yes, if it were just one file could definitely do so. However, I have about 200 files that I'm attempting to read in as a batch (I am using a for loop to read in each file, compute a "sum" based on one of the variables in the data, and output one big sheet with all the sums across files). Want to make sure I can read them in properly :) – Lizbeth Kennington Dec 21 '16 at 19:11
  • 1
    Rather than showing "what it looks like in Excel", open the data in a text editor and past the first few rows so we can see what exactly is in the file. – Ista Dec 21 '16 at 20:01
  • 1
    I created a `csv` file with the exact same data and column names and read it in R using `read.csv`. I was able to read the file and the `#` and `(` in the column names get converted to a `.`. Am I missing something? – krish Dec 21 '16 at 20:03

1 Answers1

-1

Try reading the files in using the fread() function in the data.table library? I created a similar CSV file with # in the column headers and it loaded in without any issues.

DT <- fread("11104.wav.csv")

Oliver Frost
  • 827
  • 5
  • 18