How to read CSV file in R with row title?

59 Views Asked by At

I try to read this CSV file:

enter image description here

There are 3 columns in this file. when I read it in R by read.csv("file.csv") I get:

enter image description here

It read just 2 columns instead of 3 columns and did some mixed between them

any suggestions how to solve it will be welcome

1

There are 1 best solutions below

0
Daniel Byrne On

Likely you have an extra comma somewhere not expected. For instance the data itself might contain a comma, or there is a hidden column in the data.

If you are editing in Excel, then highlight several empty columns at the end of your data and then hit the delete key. Do the same for several rows beneath the last entry, then save the file again as a csv.

Also inspect your data for spurious commas. This can happen if your data comes from a database, and someone randomly inserted a comma in your data.

Also sometimes source data stored with unicode characters that will get converted to other characters when imported into a program that is expecting UTF-8.

You can also inspect the file in notepad++, and turn on reveal codes. This will highlight all spaces and special characters. Sometimes there will be unexpected characters causing a misalignment of the data.