The following is a script file containing all R code of all sections in this slide set.

R Internal Data Set Format

data()
data(package="DMwR") # data sets from a specific package
data(package = .packages(all.available = TRUE)) # all packages
data(iris)
head(iris)
dat <- data.frame(x=rnorm(10),y=rnorm(10))
save(dat,file="exp.RData")
rm(dat)           # remove dat from the computer memory
dat               # confirming that it was deleted
load("exp.RData") # load it back from the file
head(dat)         # here it is again!

Data Sets in Text Files

library(readr)
dat <- read_csv("x.csv",col_types = "cci")
dat
dat <- read_csv2("y.csv", col_types = "ccd")
dat
dat <- read_table2("z.txt",na="???",col_types = "ccic")
dat 

Importing from Spreadsheets

dat <- read.table("clipboard",header=TRUE)
dat
library(readxl)
fc <- "c:\\Documents and Settings\\xpto\\My Documents\\calc.xls"
dat <- read_excel(fc,sheet="MayValues")
dat2 <- read_excel(fc,sheet=2)
dat <- read_excel(fc,sheet="MayValues", range="C2:F24")