Understanding Excel

Excel is a spreadsheet application developed by Microsoft to be run on Windows and Mac OS, which has a similar function to R for performing statistical computation, graphical visualization, and data modeling. Excel is provided by Microsoft with the Microsoft Office bundle, which mainly supports .xls spreadsheet data file format. In case, we want to read or write to Microsoft Excel spreadsheets from within R, we can use many available R packages. But one of the popular and working R library is xlsx.

This package programmatically provides control of the Excel files using R. The high level API of this allows users to read a spread sheet of the .xlsx document into a data.frame and writing data.frame to a file. This package is basically developed by Adrian A. Dragulescu.

Installing Excel

Here, we are considering the .xls file as the data source, which can be built and maintained with the help of Microsoft Excel 97/2000/XP/2003.

The following are the prerequisites for the xlsx packages:

  • xlsxjars
  • rJava

Installing xlsxX packages:

  • Install.packages("xlsxjars")
  • Install.packages("rJava")
  • Install.packages("xlsx")

Importing data into R

Suppose we have created one excel file and now we want to perform the data analytics related operations with R, this is the best package to load the excel file to be processed within R.

es <- read.xlsx("D:/ga.xlsx",1) 

The preceding command will store the excel data with sheet 1 into the es dataframe format in R.

Understanding data manipulation with R and Excel

The following command will be used for selecting the subset of dataframe, res, which selects the first five rows:

r <- res[1:5,]

Exporting the data to Excel

As per the defined name, the processed data with the dataframe format can be stored as a xls file to be supported with Excel.

ress <- write.xlsx(r, "D:/ga1.xls")  
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset