Home » R16 May 2017

R: Read Write CSV

This article shows how to read and write CSV file with R programming language.

We will be manually creating a new CSV file with the following data:


We name the CSV file as students.csv. The CSV file contains data of students. It contains roll no, name, gender, age, marks obtained in a subject, and address of the students.

Go to the directory where you created the above CSV file (i.e. setting working directory):

Read CSV file

Read and print the data of the students.csv file that we just created above.

Get Number of Rows and Columns in CSV

Get maximum marks in the CSV

Get the student with the highest mark

Get data of students from a particular address only, e.g. Kathmandu

Get data of students from a particular address and with a particular gender, e.g. Kathmandu & Male

Write Data to CSV

In below example, we read data from students.csv file.
Then, we filter the data by address. We only select those students whose address is Kathmandu.
After that, we write the filtered result data into a new CSV file named students-kathmandu.csv.

Hope this helps. Thanks.


Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed