Kaley W. answered 05/26/19
B.S. Computer Science Graduate
You may find the function read.csv() helpful. Its only required argument, which you can see from the help page (type ?read.csv in RStudio) is file, the name of the CSV file in quotes. You must be careful with the file path here. If I want to read a file called data.csv that is in R's current working directory, I can use read.csv("data.csv"). (You can determine the working directory using getwd().) However, if data.csv is NOT in the working directory, I must use either an absolute path or a path relative to the working directory. For example, if the absolute path to the file is "C:/Users/me/Documents/data.csv", but I am currently in "C:/Users/me", I can call read.csv("C:/Users/me/Documents/data.csv") (using an absolute pathname) or read.csv("Documents/data.csv") (using a relative pathname). A third option is to change the working directory so that read.csv("data.csv") will work. If I start in "C:/Users/me", I can change the working directory to "C:/Users/me/Documents" using setwd("C:/Users/me/Documents") (an absolute pathname) or setwd("Documents") (a relative pathname). If you would like a GUI for choosing the file, you can use read.csv(file.choose()).
The read.csv() function returns a data frame with the data from the CSV file. So I need to store that data frame somewhere if I want to be able to use it later. A variable name can be anything, but I'll choose my_data. The statement my_data <- read.csv("data.csv") reads the data in data.csv (assuming data.csv is in the working directory) and stores it in a data frame called my_data.
You may need to look at the other arguments that read.csv() takes. If the default values, as specified in the manual (from ?read.csv) don't work for you, you will need to pass in other values for those argument(s). For example, the default value for the argument header is TRUE. If data.csv does not have column headers, you should run my_data <- read.csv("data.csv", header=FALSE).