To import data in R, one common method is to use the read.csv()
function to read in a comma-separated values (CSV) file as a data frame object. Here is an example code:
main.r228 chars9 lines
This code assumes that the file my_data.csv
is located in the working directory. You can also specify the full file path if the file is located elsewhere.
There are other functions that can be used to import data in R depending on the file format, such as read.table()
for tab-delimited files and read.xlsx()
for Excel files. Check out the readr
and rio
packages as well for other data import options.
gistlibby LogSnag