How to Import a CSV to an R Notebook

February 6, 2018

(This article was first published on R Language in Datazar Blog on Medium, and kindly contributed to R-bloggers)

Adding a file to your R notebook is a simple 2 step process.

1. “Import” file to notebook session.

This makes sure your dataset is isolated in one state so that it doesn’t change as you analyze it. Remember, you can always load the latest content if you choose to later on.

To import the file, click on the “Load Files” button in your notebook. That will list all the files available for import from your current project.

Dialog box for importing file.

Click on the button next to the file (on the left). Once it’s loaded into the notebook session, the button will turn green.

File loaded.

2. Reading the file.

We can now read the CSV dataset using the read.csv() function that comes with R.

Reading the file into the notebook and dispaying the top to check.

And that’s it! The head() function allows you to see the first few lines of the dataset. That way we can check if it has been loaded. You can now use the dataset variable to access the entire CSV dataset.

All files from this post are located here so you can copy them and run again:

How to Import a CSV to an R Notebook was originally published in Datazar Blog on Medium, where people are continuing the conversation by highlighting and responding to this story.

To leave a comment for the author, please follow the link and comment on their blog: R Language in Datazar Blog on Medium. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)