[Beginner Problem] When importing a .csv file, data frame does not separate columns

Hi All!

I am new to R and I am currently following an online course to learn how to visualize univariate data (very basic stuff, I am a beginner).

So far I haven't had problems importing .csv files, but I am experiencing an issue now which I don't know how to solve. The teacher in the course imported this file correctly and a nice table appeared to her in the script.

However, when I try to import it, it comes out like this in the script and I don't know how to readjust it.

Can someone help me? Thank you!

1 Like

What code did you use to import the data?

Can you open the data file in NotePad and paste the first three lines into a response here? Place lines containing three back ticks, ```, just before and after what you paste, like this
What you paste from the file goes here.
The back tick key is just to the left of the 1 key on a US keyboard.

"K12-000031,""1/1/12"",""Stray"",""Dog"",""Spayed"",""Female"",10,""Injured or Sick"",""Chihuahua Sh Mix"",""N"",""N"",""Y"",""N"",""N"",""N"",18,6,""Toy"",""Tan & White"",3.3,""Heartworm Negative"","" 1/7/12"",""Adoption"",6"
"K12-000037,""1/1/12"",""Stray"",""Dog"",""Intact"",""Female"",3,""Normal"",""Rat Terrier Mix"",""N"",""N"",""Y"",""N"",""Y"",""Y"",14,25,""Terrier"",""White & Brown"",7.5,""No Lab Test"","" 1/3/12"",""Return to Owner"",2" ``` 

Like this?

I assume the file also has headers but I can now see a problem. Notice that the quotation marks are misplaced. The first row starts with


The comma is inside of the quotation marks. That pattern continues down the line. Even with that, when I copy your two lines into a file, I get 24 columns. Your headers are probably also corrupted in a similar way and that is confusing read.csv(). I suggest that you use the menu Edit -> Replace in Notepad to delete all of the quotation marks.

I see! I imagined something like that. Thank you very much!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

I used the Import Dataset button, not a code.

In the script it came out as

animaldata <-read.csv("C:/Users/vitto/Desktop/AnimalData.csv", quote="")