Reading Data into R REVISED

Preview:

Citation preview

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

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

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

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”)

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

Recommended