A newbie is trying to figure out how to import a simple CSV file into R

I'm new to R and I'm trying to figure out how to import a csv file so that I can follow this video: R ggplot2 Graphical histograms .

I have installed all suitable packages, including ggplot and related packages. The first instruction in the video says: afl.df=read.csv("afl_2003_2007.csv")

So, I downloaded the afl_2003_2007.csv file and tried everything that was basically, inserting the file into different directories (shared drive and then drive c). I also tried using setwd and no luck.

Explanation: I use R in windows

Please, help. Dan

WHAT I SAID AND ERRORS I RECEIVED:

 > afl.df=read.csv("afl_2003_2007.csv") Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file 'afl_2003_2007.csv': No such file or directory > afl.df=read.csv("\\the-lab.llnl.gov\llnlusers1\lopez235\Data\Documents\Dashboards,HRBI, Visulizations and Analytics\Math and Statistics and Predictive Modeling1\R Programming\afl_2003_2007.csv") Error: '\l' is an unrecognized escape in character string starting "\\the-lab.llnl.gov\l" > afl.df=read.csv("C:\Users\lopez235\Local-NOTBackedUp\R Files Local\afl_2003_2007.csv") Error: '\U' used without hex digits in character string starting "C:\U" > setwd("\\the-lab.llnl.gov\llnlusers1\lopez235\Data\Documents\Dashboards,HRBI, Visulizations and Analytics\Math and Statistics and Predictive Modeling1\R Programming\afl_2003_2007.csv") Error: '\l' is an unrecognized escape in character string starting "\\the-lab.llnl.gov\l" > setwd("\\the-lab.llnl.gov\llnlusers1\lopez235\Data\Documents\Dashboards,HRBI, Visulizations and Analytics\Math and Statistics and Predictive Modeling1\R Programming") Error: '\l' is an unrecognized escape in character string starting "\\the-lab.llnl.gov\l" > setwd("C:\Users\lopez235\Local-NOTBackedUp\R Files Local") Error: '\U' used without hex digits in character string starting "C:\U" 
+5
import r
May 02 '12 at 16:33
source share
3 answers

Use / instead of \ in your path:

 afl.df=read.csv("C:/Users/lopez235/Local-NOTBackedUp/R Files Local/afl_2003_2007.csv") 
+14
May 02 '12 at 18:33
source share

If you have problems importing datasets, I prefer to use file.choose () and then manually select the file. For example:

  newdataset <- read.csv(file.choose(), header = T) 

a window appears asking you to select the file manually, and header = T (or TRUE) tells R that these are variable names. If you have a data record header = FALSE. If you want to confirm that now R knows what variable names you can call: names (newdataset)

+2
May 30 '16 at 10:10
source share

You can use \ instead of \ afl.df = read.csv ("C: \ Users \ lopez235 \ Local-NOTBackedUp \ R Files Local \ afl_2003_2007.csv")

0
Mar 03 '16 at 5:57
source share



All Articles