|
Load Data from a CSV File
For most R users, CSV is the format of choice for ease of importing and exporting data. There are many methods available to load CSV data into R, each with their own benefit. A couple of the more common methods are detailed below.
Method 1 (Better For Small Files)
The most common method to import data from CSV files is per the read.csv function. This function is very simple and works well for smaller CSV files. The read.csv function can be a bit slow for larger CSV files however. For those files, Method 2 (below) is recommended. WorkingData = read.csv("Pathway/Filename.csv", header = T) EXAMPLE: > WorkingData = read.csv("C:/My Documents/SampleData.csv", header = T) IMPORTANT NOTES:
Method 2 (Better For Large Files)
A second method of importing data from CSVs makes use of the fread function from the data.table package. It is much more efficient (faster) when importing data from large CSV files. install.packages ("data.table") library(data.table) WorkingData = fread("Pathway/Filename.csv", header = T, sep = ',') EXAMPLE: > install.packages ("data.table") > library(data.table) > WorkingData = fread("C:/My Documents/SampleData.csv", header = T, sep = ',') IMPORTANT NOTES:
|