Read and Load Data in R
Learn how to read and load data from various sources using R.
Read and load data from various sources
The journey of data analysis begins with managing data sources. File management in the R language is critical for many practices. It enables users to:
- Organize and manage data efficiently
- Save time and effort
- Eliminate potential version errors
- Keep track of changes
- Share data with colleagues
Data can be read from a variety of sources, with the most common being comma-separated values (CSV), Microsoft Excel (XLS, XLSX), and RData files (RData, RDS). We utilize different functions to get data from various sources.
Read CSV files
A comma-separated values (CSV) file is a plain text file that stores tabular data (numbers and text) in plain-text form. Each line in a CSV file represents a row of the table, and each column within that row is separated by a comma.
CSV is one of the most widely used formats in the industry. R has incorporated built-in functions to facilitate the reading of CSV files. We can use the read.csv()
function to read a CSV file by passing its directory to it.
df <- read.csv('Documents/Crime.csv') # Pass in the directory of the file to readprint(head(df,5)) # Print the first 5 row of the data frame
Note: The
head(data,x)
function allows the selection ...