How to write a text file through R?

This recipe helps you write a text file through R

Recipe Objective

How to write a text file through R? Creating a new file or any format say.csv , etc and writing the data generated inside that file is nothing but writing a text file in R. For instance, we create a 4*5 matrix in our example. We then pass this matrix through a dataframe. Using the write () function this matrix is written/displayed inside a new.csv file is stored inside the files folder. This recipe demonstrates an example of how to write a file.

Step 1 -Creating a 4*5 matrix in a vector m

m <- matrix(c(1:10), nrow = 4, ncol = 5, byrow = TRUE) print(m)

Step 2 -Create a dataframe for the matrix

df <- data.frame(m)

Step 3 -Write a text file

Using the write.csv() function the matrix created gets written/displayed in the new csv file named'example file.csv'. This file can be accessed from the files folder. syntax - write.csv(data,filename) where, data - the created data filename - the name of the file in which you wish to save your data

write.csv(df,"example file.csv")

What Users are saying..

profile image

Savvy Sahai

Data Science Intern, Capgemini
linkedin profile url

As a student looking to break into the field of data engineering and data science, one can get really confused as to which path to take. Very few ways to do it are Google, YouTube, etc. I was one of... Read More

Relevant Projects

Learn Hyperparameter Tuning for Neural Networks with PyTorch
In this Deep Learning Project, you will learn how to optimally tune the hyperparameters (learning rate, epochs, dropout, early stopping) of a neural network model in PyTorch to improve model performance.

Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

Learn How to Build a Logistic Regression Model in PyTorch
In this Machine Learning Project, you will learn how to build a simple logistic regression model in PyTorch for customer churn prediction.

Build Multi Class Text Classification Models with RNN and LSTM
In this Deep Learning Project, you will use the customer complaints data about consumer financial products to build multi-class text classification models using RNN and LSTM.

Build a Multi Touch Attribution Machine Learning Model in Python
Identifying the ROI on marketing campaigns is an essential KPI for any business. In this ML project, you will learn to build a Multi Touch Attribution Model in Python to identify the ROI of various marketing efforts and their impact on conversions or sales..

Build a Graph Based Recommendation System in Python-Part 2
In this Graph Based Recommender System Project, you will build a recommender system project for eCommerce platforms and learn to use FAISS for efficient similarity search.

Census Income Data Set Project-Predict Adult Census Income
Use the Adult Income dataset to predict whether income exceeds 50K yr based oncensus data.

Build a Credit Default Risk Prediction Model with LightGBM
In this Machine Learning Project, you will build a classification model for default prediction with LightGBM.

Build a Multi-Class Classification Model in Python on Saturn Cloud
In this machine learning classification project, you will build a multi-class classification model in Python on Saturn Cloud to predict the license status of a business.

Build Deep Autoencoders Model for Anomaly Detection in Python
In this deep learning project , you will build and deploy a deep autoencoders model using Flask.