Documentation:Importing data in RStat on a mac computer from excel files

From UBC Wiki

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("/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. /users/documents as the working directory for a file and path /users/documents/myfile.txt)

To do this, use the following code
>setwd("/users/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 misc. tab in the top menu, select change working directory, and selecting the directory you wish to change to. and example of the ways to change your directory are shown below.

RStat user interface


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 these links

Documentation:Importing data in RStat on a windows computer from CSV and text files
Documentation:Importing data in RStudio on a windows computer from excel files ‎
Documentation:Importing data in RStat on a mac computer from text and CSV files
Documentation:Importing data in RStudio on a mac computer from text and CSV 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 RStudio on a windows computer from CSV and text files