Site icon R-bloggers

How to Import a CSV to an R Notebook

[This article was first published on R Language in Datazar Blog on Medium, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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: https://www.datazar.com/project/p820a77e6-1555-4549-8a6f-96ca99c29ff8/files


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.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.