How to Read CSVs in R

03.26.2021

R provides many ways to read data into memory. Many ways are to pull tables into dataframes and vectors. In this article, we will learn how to read csvs in R.

To read csv functions, we can use the read_csv function. This will grab the contents of a csv and add it to a R dataframe.

df = read_csv('data.csv')

If our csv doesn't have column names, we can also use the col_names paramter.

df = read_csv('data.csv', col_names = FALSE)

There are many usefull options when reading a csv such as specifying the delimeter, hanldling empty values, etc. Use the ?read_csv command to see more options.

For example, if we want to skip a few rows at the top of our file, we can use the skip paramter. The exaple below wil skip 3 rows before parsing the csv.

df = read_csv('data.csv', skip=3)