Opening a csv file

I’m having a lot of trouble opening a certain csv file. I have to do this for my study and everyone else seems to be able to open it fine but mine doesn’t for some reason.
There are supposed to be two rows; var1 and var2. However, the file is opened as one row and this messes up the plot I’m supposed to make. Does anyone know how to fix this?

Without some sample data, this is just a guess but it seems likely that you may need to specify the separator between the 2 columns of data.

Probably the easiest way to check this is to open the file in a text editor and see if the fire is using an unusual separater.

As examples of different separators

dat1 <-   read.csv("mydata.csv", sep = ",")


dat1 <-   read.csv("mydata.csv", sep = "\t")


dat1 <-   read.csv("mydata.csv", sep = ";")
1 Like

This is the CSV file I'm working with. I tried the different separators but they all rendered the same result

The Image below is the lines I have used on the file a1_data1, and the result of plotting is is on the right while it should be a concave spread instead of a straight line

Hi Olivier,

First, welcome to R Studio Community forums.

I suggest you to use the import dataset tool in the menu. You can click in the upper left menu File > Import Dataset > From Text (Base) and select the file to import it. Then you can copy the code that appears in the R console with the code required for import the data in .csv and then copy it in your script in order to have a more reproducible script.

Hope it helps.


Thank you! This helped a lot in finding what was wrong with the excel file!

Kind regards,

1 Like

The solution was that there were too many quotation marks in the file which messed it up in Rstudio. I removed them and the data became clear in R immediately.

This topic was automatically closed 7 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.