R Language using Excel Files


INTRODUCTION:

This document highlights the process of reading excel files using R language. There are several

ambiguous suggestions already prevailing in the web. So, we have tried to figure out 2 best

possible ways to solve the ambiguities. Here, they are described in brief:




READING EXCEL FILES:

1ST SOLUTION:


install.packages("gdata")                [ It can be done manually too. Go to Packages at the


                                         top. Select any location, preferably USA (CA 1).


                                         Then select gdata from the list. ]


library(gdata)                           [ Use of Library for reading an Excel file. ]


setwd("D:/R Statistics")                  [ Set working directory ]


y=read.xls("iris.xls")                    [Read the .xls/.xlsx file that is present in the working


                                          directory. ]


y                                         [ Print the contents of the excel file. ]
2ND SOLUTION:


install.packages("xlsx")                   [ It can be done manually too. Go to Packages at the


                                           top. Select any location, preferably USA (CA 1).


                                           Then select xlsx from the list. ]




require(xlsx)                              [ Ask for xlsx functionalities. ]


file=system.file("tests","test_import.xlsx",package ="xlsx")


                                           [ “tests” is the name of folder where the xlsx file is


                                           saved. “test_import.xlsx” is the xlsx file belonging


                                           to the package “xlsx”. Folder, file and package


                                            name may be other than these. ]


a=read.xlsx(file,1)                        [ We have to read the file , at the same time mention


                                            its sheet no , i.e. 1,2,3…… ]


a                                           [ Print the contents of the excel file. ]


CONCLUSION:

The above mentioned 2 ways are really worth reading an Excel file using R. Writing in an Excel

file using R is still under supervision.

R with excel

  • 1.
    R Language usingExcel Files INTRODUCTION: This document highlights the process of reading excel files using R language. There are several ambiguous suggestions already prevailing in the web. So, we have tried to figure out 2 best possible ways to solve the ambiguities. Here, they are described in brief: READING EXCEL FILES: 1ST SOLUTION: install.packages("gdata") [ It can be done manually too. Go to Packages at the top. Select any location, preferably USA (CA 1). Then select gdata from the list. ] library(gdata) [ Use of Library for reading an Excel file. ] setwd("D:/R Statistics") [ Set working directory ] y=read.xls("iris.xls") [Read the .xls/.xlsx file that is present in the working directory. ] y [ Print the contents of the excel file. ]
  • 2.
    2ND SOLUTION: install.packages("xlsx") [ It can be done manually too. Go to Packages at the top. Select any location, preferably USA (CA 1). Then select xlsx from the list. ] require(xlsx) [ Ask for xlsx functionalities. ] file=system.file("tests","test_import.xlsx",package ="xlsx") [ “tests” is the name of folder where the xlsx file is saved. “test_import.xlsx” is the xlsx file belonging to the package “xlsx”. Folder, file and package name may be other than these. ] a=read.xlsx(file,1) [ We have to read the file , at the same time mention its sheet no , i.e. 1,2,3…… ] a [ Print the contents of the excel file. ] CONCLUSION: The above mentioned 2 ways are really worth reading an Excel file using R. Writing in an Excel file using R is still under supervision.