I have an excel file that I want to open in R. I tried both of these commands after saving the excel file as a csv file or a text file.
read.table() or read.csv()
I think part of the problem is where the file is located. I have it saved on the desk top. What am I missing here?
Here is the R output
In file(file, "rt") : cannot open file 'Rtrial.csv': No such file or directory > help.search("read.csv") > read.csv("Rtrial.csv") Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file 'Rtrial.csv': No such file or directory > read.table("tab")
you can use the command file. choose() and then follow the menu to find the file you want. This function will return the correct path to the file. Paths become much easier to deal with if you use projects in Rstudio (file -> new project), as then you can use relative paths from the project directory.
To load a. csv file into the current script and operate with it, use the read. csv() method in base R. The output is delivered as a data frame, with row numbers given to integers starting at 1.
You can use getwd() (to find the current path of the R process) or file. choose() to interactively find the file (it will return a character of the full path to the file). If you don't want to learn from this and/or do it with different files all the time, then you can short-circuit it with read. csv(file.
To throw out another option, why not set the working directory (preferably via a script) to the desktop using setwd('C:\John\Desktop')
and then read the files just using file names
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With