How to export a file in R?

963    Asked by Tanyaverma in Data Science , Asked on Nov 9, 2019
Answered by Nitin Solanki

There are two types of files most commonly used in R.

a)CSV File

CSV or comma separated values are those files that contain data separated by commas.

b) Excel File

Excel files are those files that contain data separated by tabs.

To export or to write a CSV file, we can use

write.csv(df, file = "foo.csv")

Here, ‘foo.csv’ is the filename on which we are exporting

To export an excel file, we can use a library ‘xlsx’

install.packages('xlsx',repos="http://cran.rstudio.com/")

library(xlsx)

Let us build a dataframe of a matrix containing numbers from 1 to 10.

df <- data.frame(matrix(1:10))

write.xlsx(df, "output.xlsx")

Here, ‘output.xlsx’ is the name of the filename which we will export



Your Answer

Interviews

Parent Categories