Lee Kuo
Lee Kuo

Reputation: 23

Import CSV file using R

I'm trying to import my csv file by using

data = read.csv(C:\Users\ldayz\OneDrive\Documents\rating) 

but I keep getting this error message

Error: unexpected symbol in "data = read.csv(C:\Users".

I copied the files directory from details so it should be accurate. Am I missing some signs here?

Upvotes: 1

Views: 1266

Answers (1)

madam_fledershrew
madam_fledershrew

Reputation: 33

I usually create my Rscript within my directory to avoid having to spell out the location to R.

If you don't have the folder you need pulled up, that's okay. In the window below the global environment, click the three dots in the right corner (red box in the picture). enter image description here

Once you've done that, a window will pop up. It'll say "go to folder" enter image description here

Find your way to the folder that your file is kept in. When you've found it, click "open". The folder you want/need should now be displayed in the window below the global environment.

To set the folder to your directory, click the settings (the little gear) icon in the window below your global environment. You'll see several options. Click "set as working directory".

enter image description here

If this works your console should spit out something like this:

 setwd("C:/Users/madam_fledershrew/Desktop/ENVS 492")

From there you should be able to read in the .csv file using this code:

nameofobject=read.csv("name of file.csv", stringsAsFactors = T)

Hope this helps.

Upvotes: 1

Related Questions