R Data Exporting

Data Exporting

  • R can also write data to external files
  • R can write in various file formats like csv, xlsx, xml etc…
  • Steps to store the data externally are as follows:
    • Step 1: Set the path of the location to the file’s location
    • getwd() # gives the current directory
    • setwd(“path”) # sets the path, e.g. setwd(“D:/R/dataset/”)
    • Step 2: Select the object (vector, matrix, dataframe etc…) that should be stored, e.g. sampledata
    • Step 3: Use ‘write’ command to store the data
    • write.csv () # writes to .csv file
    • write.xlsx () # writes to .xlsx file
    • write.table() # writes to .txt files
Syntax
write.xlsx(sampledata, file = "sample.xlsx", sheetName = "Sample")

If we need to save the object ‘tk’ to “d:/R/” location as a file with name “Truck”

Data Exporting in r language

Step 1: Set the path

Syntax
setwd("d:/R/")

Step 2: Ensure xlsx package is installed

xlsx package in r language

Step 3: Use write.xlsx () from xlsx package

CODE/PROGRAM/EXAMPLE
write.xlsx(tk, "Truck.xlsx", sheetName = "Details")
#Data_Exporting_r_language #Data_Exporting_r_programming #getwd()_function_in_r_language #getwd()_function_in_r_programming

(New page will open, for Comment)

Not yet commented...