Reading data
    into                REVISED

  2012-10-05@HSPH
 Kazuki Yoshida, M.D.
  MPH-CLE student

                        FREEDOM
                        TO	
  KNOW
Previously in this group
n   Introduction to R

n   Reading Data into R (1)




                  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
        Statistics          Programming
n   None            n   Install/Load packages

                     n   read.____() functions

                     n   <- (assignment)
http://mediacrushllc.com/2012/internet-statistics-2012/




                            is the study of the
collection, organization, analysis, interpretation,
               and presentation of



               data
                 http://en.wikipedia.org/wiki/Statistics
Supported
n   .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
Workspace

Console
            Plot
Tools-Options
Restart RStudio
after cofiguration
Working directory?

 Folder your are
   working in
CRAN
mirror
Comprehensive
      R                             You get
                                  additional
      Archive                   functionalities
                                  from here!
      Network
http://cran.r-project.org/web/packages/
   available_packages_by_date.html
Create
a script
Source    Workspace


Console     Plot
Install
additional
packages
Install packages!   foreign sas7bdat XML
                      gdata
                       xlsx
programming
way to load it   Click to load
library(gdata)
                  packages
Use text file
such as csv
 if possible
Download comma-separated and Excel




 Put them in folder
BONEDEN.DAT.txt
BONEDEN.DAT.xls
        http://www.cengage.com/cgi-wadsworth/course_products_wp.pl?
                 fid=M20bI&product_isbn_issn=9780538733496
For comma-, tab-, or
space-separated text,
  GUI is available
Text
name of a dataset here
                               file name here



bone <- read.csv(“BONEDEN.DAT.txt”)



  function to read .csv files
Excel next
Use gdata package



             library(gdata)
bone <- read.xls(“BONEDEN.DAT.xls”)
Use xlsx package



                     library(xlsx)
bone <- read.xlsx(“BONEDEN.DAT.xls”, sheetIndex = 1)
Never type all

      Always hit TAB
                   http://www.clickykeyboards.com/index.cfm/fa/
                 items.main/parentcat/10191/subcatid/0/id/179764
Never type all


    F1 for help
                  Always hit TAB
                             http://www.clickykeyboards.com/index.cfm/fa/
                           items.main/parentcat/10191/subcatid/0/id/179764
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”)
HTML table!

             http://
         www.drugs.com/
        top200_2003.html
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
        Statistics          Programming
n   None            n   Install/Load packages

                     n   read.____() functions

                     n   <- (assignment)
Reading Data into R REVISED

Reading Data into R REVISED