Graphics Reference
In-Depth Information
$ Sex : Factor w / 2 levels "F" , "M" : 1 2 NA
$ Number: int 2 49 21
Alternatively, you could load the file with strings as factors, and then convert individual columns
from factors to characters.
See Also
read.csv() is a convenience wrapper function around read.table() . If you need more con-
trol over the input, see ?read.table .
Loading Data from an Excel File
Problem
You want to load data from an Excel file.
Solution
The xlsx package has the function read.xlsx() for reading Excel files. This will read the first
sheet of an Excel spreadsheet:
# Only need to install once
install.packages( "xlsx" )
library(xslx)
data <- read.xlsx( "datafile.xlsx" , 1 )
For reading older Excel files in the .xlsformat, the gdata package has the function read.xls() :
# Only need to install once
install.packages( "gdata" )
library(gdata)
# Read first sheet
data <- read.xls( "datafile.xls" )
Discussion
With read.xlsx() , you can load from other sheets by specifying a number for sheetIndex or
a name for sheetName :
data <- read.xlsx( "datafile.xls" , sheetIndex = 2 )
data <- read.xlsx( "datafile.xls" , sheetName = "Revenues" )
Search WWH ::




Custom Search