Documentation:Importing data in RStudio on a windows computer from excel files
It can sometimes be useful to read Data in from another file using R. There are a few different ways this can be accomplished using both Rstat and Rstudio. The file type discussed in this article is an excel file.
To import data from an excel file you must have the xlsx and rJava packages installed. If you have already installed rJava and Xlsx you may skip this section.
To install these packages you must have administrator access to your computer, As well as Java 64-bit installed. Use the following commands to install.
>install.packages("rJava")
>install.packages("xlsx")
Once rJava and xlsx are installed you must import the library for xlsx into your command prompt. You are ready to read data from excel files from this point on. Use the commands.
>library("xlsx") #Imports the xlsx library for use
>mydata= read.xlsx("c:/mydata.xlsx", header=TRUE)
read.xlsx's first argument takes the path to the file. It's second argument will take the name of the sheet you wish to import.
If you plan to extract multiple files from the same working directory, it may be beneficial to set the location of those files as your working directory(eg. c:/users/documents as the working directory for a file and path c:/user/documents/myfile.txt)
To do this, use the following code
>setwd("C:/Documents and Settings/username/My Documents/x/y/z")
Note: R will not be able to read files located outside your working directory.
Alternatively, you can set your working directory by clicking the file tab in the top menu->change dir...>and then selecting the directory you wish to work from. And example is shown below.
To check data that has already been parsed into R type the name of the variable that you saved the data to (eg. type mydata to view the data) or if you want to view a single column of the data, type the variable name, followed by [#], where # is the number of the column you wish to view.
You may also be interested in.
Documentation:Importing data in RStudio on a mac computer from text and CSV files
Documentation:Importing data in RStudio on a windows computer from CSV and text files
Documentation:Importing data in RStat on a mac computer from text and CSV files
Documentation:Importing data in RStat on a mac computer from excel files
Documentation:Importing data in RStudio on a mac computer from excel files
Documentation:Importing data in RStat on a windows computer from excel files
Documentation:Importing data in RStat on a windows computer from CSV and text files