Search code examples
rcsvrstudiodata-analysis

my computer can't find my csv file in r


When I try to run my csv file in RStudio, it says

"cannot open file 'bit121GBP.csv': No such file or directory
Error in file(file, "rt") : cannot open the connection"
mydata <- read.csv("bit121GBP.csv", header =TRUE)

Should I download it to a different place, because right now it's on my Desktop, or should I change the code?


Solution

  • There are three ways you can read file.

    For example, you have to downloaded in Desktop (example for mac) then

    First: provide full path

    mydata <- read.csv("/Users/test/Desktop/bit121GBP.csv", header =TRUE)
    

    Second: Provide relative path

    mydata <- read.csv("~/Desktop/bit121GBP.csv", header =TRUE)
    

    Third: Set path

    setwd("~/Desktop")
    mydata <- read.csv("bit121GBP.csv", header =TRUE)