Reading data into
2012-10-05@HSPHKazuki Yoshida, M.D. MPH-CLE student
FREEDOMTO KNOW
REVISED
n Introduction to R
n Reading Data into R (1)
Previously in this group
Group Website: http://rpubs.com/kaz_yos/useR_at_HSPH
Menu
n Configuring RStudio
n Installing/Loading packages
n Reading text files in
n Reading excel files in
n (Reading other files in)
Ingredients
n None n Install/Load packages
n read.____() functions
n <- (assignment)
Statistics Programming
is the study of the collection, organization, analysis, interpretation,
and presentation of
datahttp://en.wikipedia.org/wiki/Statistics
http://mediacrushllc.com/2012/internet-statistics-2012/
Supportedn .RData (native): load()
n .csv & text files: read.csv(), etc
n .xls/.xlsx: library(gdata) or library(xlsx)
n .sas7bdat: read.sas7bdat() via library(sas7bdat)
n .dta: read.dta via library(foreign)
n and more...http://cran.r-project.org/doc/manuals/R-data.html
Create a folder for this study group
This will be your working directory.
First configure Studio
Open R Studio
ConsolePlot
Workspace
Tools-Options
Restart RStudioafter cofiguration
Working directory?
Folder your are working in
CRANmirror
Comprehensive
RArchive
Network
http://cran.r-project.org/web/packages/available_packages_by_date.html
You get additional
functionalities from here!
Createa script
Source
Console Plot
Workspace
Install additional packages
foreign sas7bdat XML
gdataxlsx
Install packages!
Click to loadpackageslibrary(gdata)
programming way to load it
Use text filesuch as csvif possible
http://www.cengage.com/cgi-wadsworth/course_products_wp.pl?fid=M20bI&product_isbn_issn=9780538733496
Download comma-separated and Excel
BONEDEN.DAT.txtBONEDEN.DAT.xls
Put them in folder
For comma-, tab-, or space-separated text,
GUI is available
Text
bone <- read.csv(“BONEDEN.DAT.txt”)
name of a dataset herefile name here
function to read .csv files
Excel next
library(gdata)bone <- read.xls(“BONEDEN.DAT.xls”)
Use gdata package
library(xlsx)bone <- read.xlsx(“BONEDEN.DAT.xls”, sheetIndex = 1)
Use xlsx package
Always hit TABhttp://www.clickykeyboards.com/index.cfm/fa/
items.main/parentcat/10191/subcatid/0/id/179764
Never type all
Always hit TABhttp://www.clickykeyboards.com/index.cfm/fa/
items.main/parentcat/10191/subcatid/0/id/179764
Never type all
F1 for help
Follow on-site instructions
library(foreign)bone <- read.xport(“BONEDEN.DAT.xpt”)
or
library(sas7bdat)bone <- read.sas7bdat(“BONEDEN.DAT.sas7bdat”)
library(foreign)
bone <- read.dta(“BONEDEN.DAT.dta”)
http://www.drugs.com/top200_2003.html
HTML table!
library(XML)
drug2003 <- readHTMLTable("http://www.drugs.com/top200_2003.html", which = 2, skip.rows = 1)
Menu
n Configuring RStudio
n Installing/Loading packages
n Reading text files in
n Reading excel files in
n (Reading other files in)
Ingredients
n None n Install/Load packages
n read.____() functions
n <- (assignment)
Statistics Programming