CodeInfoNet

Learn programming on the go!

Home » How to import a .Csv file in R

How to import a .Csv file in R

In this article we are going to learn about how to import a .Csv file in R programming. At the end of this article you will be able to import a .csv file in R without any issue.

Just to have a recap of what we did in our previous article, previous article was to learn about basic plotting technique in R programming. We made a use of matplot() function to plot our subsets. If you have missed it, here is a link “Subsetting & visualizing the subsets using matplot() function

Before starting to import files, we will just go through some of the features of R programming.

  • R is designed in such a way that there is a minimum work for a data scientist when it is related to formatting the data, collecting a data, visualizing and all other data related stuffs.
  • If we consider a functionality of importing file in other programming languages, we may need to write lots of lines of code then separate code for fetching the data storing it in data table, list, or other object…. And the task list is never ending.
  • But, In R programming, we just need to write 1-2 lines to import the data and store it in a variable.
  • Another amazing fact about R is, when we import the csv file into it, it automatically stores the data in tabular format. Also, it creates a data frame from the file

Let’s see the function we are talking about straight away:

read.csv() function:

This function is used to import a csv file into R. This function has many parameters but they are optional. It means even if we don’t specify these parameters, our file will be imported as it is. Only one condition, file should be in proper format.

There are 2 ways with which we can use the read. csv() function. We can use them as an when needed. Both ways are very simple to implement.

  1. Selecting & uploading a file when prompted.
  2. Get/Set working directory

Lets see one by one.

Sumit Rajguru

Back to top