having difficulty in reading CSV file

I apologize for I am new here, so hello. I am currently in a graduate course and I am feeling discouraged as I have tried numerous times to perfect this code and I am still getting an Error message. Any tips?

data<-read.csv('/Users/mopopo/Desktop/Econ5370/ps1_q2.csv',header=TRUE)

the error message is
error: unexpected input in "Data<-read.csv('/Users/mopopo/Desktop/Econ5370/ps1_q2.csv',"

should work, but try double quotes

Data  <-  read.csv("/Users/mopopo/Desktop/Econ5370/ps1_q2.csv",header=TRUE)

(Don't use lower case data, because that's the name of a function. Same with df, although you can often get away with it. And it's good practice to put a space before an after operators, such as <- .)

Better yet

install packages("readr")

and

Data <- read_csv("/Users/mopopo/Desktop/Econ5370/ps1_q2.csv")

which does a generally better job of assigning the correct variable type.

1 Like

An easy way to do this is to use the "Import Dataset" button in Rstudio. It is located in the environment tab (top right panel of Rstudio by default). See the screenshot:
image

Your colour scheme is likely different, but you should be able to find that button. It will allow you to select the file using a graphical interface, and then will show you the code required for importing in future.

If you still receive an error message about "unexpected input", then double check that your CSV file is as expected - I believe that error may be caused by unexpected characters or symbols or a malformed CSV file.

1 Like

thanks, it really works! :laughing:

Thanks! It can be a good method to apply in real case, but I have to submit my codes :slight_smile:

You could use file.choose() in the console. Appear a new window and select the file. The console show the path or directory of his file. Copy and paste the path.

Is very fast solution.

data<-read.csv("path",header=T)

1 Like

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.