How to write a csv through R?

How to write a csv through R?

How to write a csv through R?

This recipe helps you write a csv through R


Recipe Objective

CSV stands for Comma Separated Value. .csv is a text file which is used to store tabular data where usually text is separated by comma. It is quite widely used as a data source where each line is a data record.

R gives you the platform to read, write and edit data that are stored in any external environment.

In this recipe we will discuss how to write a CSV file in R.

Step 1: Creating a Dataframe

We use data.frame() function to create a dataframe using vectors.

data = data.frame(Name = c("Nikhil", "Fredo", "Sam"), AGE = c("15", "34", "45"), Hobbies = c("Football", "Reading", "Swimming")) ​
Nikhil	15	Football
Fredo	34	Reading
Sam	45	Swimming

Step 2: Writing a CSV file

We use write.csv() function to write csv file.

Syntax: write.csv(x, file, row.names, quote)


  1. x = dataframe that you want to write;
  2. file = name along with the extension .csv;
  3. row.names = (Optional) Input FALSE if you don't want row labels in your CSV file. By default, it's TRUE
  4. quote = (Optional) Input FALSE if you don't want double quotes in text content. By default, it's TRUE
write.csv(data, "dftocsv.csv", quote = FALSE)

Relevant Projects

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

NLP and Deep Learning For Fake News Classification in Python
In this project you will use Python to implement various machine learning methods( RNN, LSTM, GRU) for fake news classification.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.