2

Why is 'ï..' at the front of the first colname when imported a csv into r?

This happens whenever I have a csv saved via excel and then do read.csv() in r. What causes this behavior?

Dput:

structure(list(ï..Species = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 4L, 5L, 6L, 7L, 1L, 3L, 1L, 2L, 2L, 4L, 4L, 3L, 2L, 5L, 4L, 7L, 2L, 2L), Country = c(1L, 1L, 1L, 1L, 2L, 2L, 3L, 4L, 5L, 6L, 1L, 3L, 2L, 1L, 2L, 5L, 4L, 4L, 2L, 3L, 3L, 5L, 4L, 5L, 5L, 3L, 7L, 4L, 5L)), class = "data.frame", row.names = c(NA, -29L))

Bohnston
  • 69
  • 10
  • It would help to see your code, your input data and your expected output. Otherwise we are only guessing. – Limey Jan 21 '21 at 13:26
  • Please show your code. Are you writing the CSV file using R as well, or only reading it? – Bill the Lizard Jan 21 '21 at 13:26
  • I am only reading a csv in r. The file is saved in excel as a csv. The code is just 'read.csv(filename.csv) – Bohnston Jan 21 '21 at 13:46
  • @Bohnston that makes it easier to post your actual code and an example of your file. Post the **actual code** that produces what you describe, and the **actual** output. Not something like it. Don't expect people to try to reproduce what you claim. It's quite obvious others *don'* have the same issue. – Panagiotis Kanavos Jan 21 '21 at 14:04
  • If the file is a Unicode file with a BOM, it doesn't start with `i` at all – Panagiotis Kanavos Jan 21 '21 at 14:05

1 Answers1

3

Please review previous answer here regarding weird characters when importing data from Excel: Weird characters added to first column name after reading a toad-exported csv file

  • 2
    You should explain why this is relevant - the file may be a Unicode file with a BOM. The solution is to use the correct file encoding in `read_csv` – Panagiotis Kanavos Jan 21 '21 at 14:05
  • This was the reason why, I added the correct file encoding and the strange character goes. – Bohnston Jan 21 '21 at 14:42