R programming is one of the very powerful languages specially used for data analytics in various fields. Analysis of data means reading and writing data from various files like excel, CSV, text files, etc. Today we will be dealing with various ways of writing data to different types of files using R programming.
Writing Data to CSV files
CSV stands for Comma Separated Values. These files are used to handle a large amount of statistical data. Following is the syntax to write to a CSV file:
write.csv(my_data, file = "my_data.csv") write.csv2(my_data, file = "my_data.csv")
csv2()are the function in R programming.
write.csv() uses “.” for the decimal point and a comma (“, ”) for the separator.
write.csv2() uses a comma (“, ”) for the decimal point and a semicolon (“;”) for the separator.
Writing Data to text files
Text files are commonly used in almost every application in our day to day life as a step for the “Paperless World”. Well, writing to .txt files is very similar to that of the CSV files. Following is the syntax to write to a text file:
write.table(my_data, file = “my_data.txt”, sep = “”)
Writing Data to Excel files
To write data to excel we need to install the package known as “xlsx package”, it is basically a java based solution for reading, writing, and committing changes to excel files. It can be installed as follows:
and can be loaded as:
General syntax of using it is:
write.xlsx(my_data, file = “result.xlsx”, sheetName = “my_data”, append = FALSE).
- Writing CSV files in Python
- Writing Data in Tabular form to Files in Julia
- Reading Files in R Programming
- Reading Tabular Data from files in R Programming
- Working with CSV files in R Programming
- Working with XML Files in R Programming
- Working with Excel Files in R Programming
- Working with Binary Files in R Programming
- Working with JSON Files in R Programming
- CSS | writing-mode Property
- Perl | Writing to a File
- Analytical Writing Section in GRE General
- How to open a PDF files in web browser using PHP?
- Creating a dataframe using Excel files
- Deleting all files from a folder using PHP
- How to include() all PHP files from a directory ?
- Perl | Creating Excel Files
- How to recursively delete a directory and its entire contents (files + sub dirs) in PHP?