Using packages and functions in R
A. Installing the package: install.packages(“XLConnect”) B. Load the package in R: library(XLConnect) Also if you need help run this command: help(“XLConnect”“) C. Load the excel workbook into R. loadWorkbook(filename, create=TRUE)
#Using the excel spreadsheet provided in the classroom, regarding the example of blood pressure.
library(XLConnect)
## Loading required package: XLConnectJars
## XLConnect 0.2-12 by Mirai Solutions GmbH [aut],
## Martin Studer [cre],
## The Apache Software Foundation [ctb, cph] (Apache POI, Apache Commons
## Codec),
## Stephen Colebourne [ctb, cph] (Joda-Time Java library),
## Graph Builder [ctb, cph] (Curvesapi Java library)
## http://www.mirai-solutions.com ,
## http://miraisolutions.wordpress.com
help("XLConnect")
bloodp = loadWorkbook("bloodpress.xlsx", create=TRUE)
data = readWorksheet(bloodp, sheet = "systolic", startRow = 0, endRow = 10, startCol = 0, endCol = 0)
data
## Nothing LowSalt WOSalt LowDose HighDose
## 1 180 172 163 158 147
## 2 173 158 170 146 152
## 3 175 167 158 160 143
## 4 182 160 162 171 155
## 5 181 175 170 155 160
We can also use the following functions: writeWorksheet(), createName(), writeNamedRegion(), saveWorkbook(), writeWorksheetToFile(), writeNamedRegion1ToFile(), among others.
require(xlsx)
## Loading required package: xlsx
## Loading required package: rJava
## Loading required package: xlsxjars
##
## Attaching package: 'xlsx'
## The following objects are masked from 'package:XLConnect':
##
## createFreezePane, createSheet, createSplitPane, getCellStyle,
## getSheets, loadWorkbook, removeSheet, saveWorkbook,
## setCellStyle, setColumnWidth, setRowHeight
dat <- read.xlsx("bloodpress.xlsx", sheetName = "systolic") # reading file from class.
dat
## Nothing LowSalt WOSalt LowDose HighDose
## 1 180 172 163 158 147
## 2 173 158 170 146 152
## 3 175 167 158 160 143
## 4 182 160 162 171 155
## 5 181 175 170 155 160
## Description:
library(help="gdata")
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.