This is an R Markdown document for the course ‘Computing in R’. Using this document, you can easily run selected pieces of R code shown during the lectures from within RStudio.
2+7
## [1] 9
sqrt(2)
## [1] 1.414214
cos(pi)
## [1] -1
log10(10^3)
## [1] 3
x <- 2
print(x)
## [1] 2
x
## [1] 2
x^2
## [1] 4
x
## [1] 2
#y < - x
help(sqrt)
library()
help(read.dta)
## No documentation for 'read.dta' in specified packages and libraries:
## you could try '??read.dta'
??read.dta
library(foreign)
help(read.dta)
help(package = stats)
help.start()
## If nothing happens, you should open
## 'http://127.0.0.1:19432/doc/html/index.html' yourself
help(mean)
# ? is a shorthand for help()
?mean
x <- c(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
x
## [1] 10 9 8 7 6 5 4 3 2 1
x <- seq(from = 10, to = 1, by = -1)
x
## [1] 10 9 8 7 6 5 4 3 2 1
x <- seq(10, 1)
x
## [1] 10 9 8 7 6 5 4 3 2 1
x <- 10:1
x
## [1] 10 9 8 7 6 5 4 3 2 1
x[5]
## [1] 6
x[10]
## [1] 1
x[5] + x[10]
## [1] 7
indx <- c(5,10)
indx
## [1] 5 10
x[indx]
## [1] 6 1
x[c(5,10)]
## [1] 6 1
c(-5, -10)
## [1] -5 -10
x[c(-5, -10)]
## [1] 10 9 8 7 5 4 3 2
x[4] <- 12
x
## [1] 10 9 8 12 6 5 4 3 2 1
mean(x)
## [1] 6
x + 1
## [1] 11 10 9 13 7 6 5 4 3 2
2*x
## [1] 20 18 16 24 12 10 8 6 4 2
help(matrix)
A <- matrix(data = 1:10, nrow = 2, ncol = 5)
A <- matrix(1:10, 2, 5)
A
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 3 5 7 9
## [2,] 2 4 6 8 10
A[2, 3]
## [1] 6
A[2,3] <- 12
A[1, ]
## [1] 1 3 5 7 9
A[1,1:5]
## [1] 1 3 5 7 9
A[, c(1, 5)]
## [,1] [,2]
## [1,] 1 9
## [2,] 2 10
A[1:2, c(1,5)]
## [,1] [,2]
## [1,] 1 9
## [2,] 2 10
dim(A[, c(1, 5)])
## [1] 2 2
#x[1,3]
x[c(1,3)]
## [1] 10 8
ls()
## [1] "A" "indx" "r" "x"
summary(x)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.00 3.25 5.50 6.00 8.75 12.00
summary(A)
## V1 V2 V3 V4 V5
## Min. :1.00 Min. :3.00 Min. : 5.00 Min. :7.00 Min. : 9.00
## 1st Qu.:1.25 1st Qu.:3.25 1st Qu.: 6.75 1st Qu.:7.25 1st Qu.: 9.25
## Median :1.50 Median :3.50 Median : 8.50 Median :7.50 Median : 9.50
## Mean :1.50 Mean :3.50 Mean : 8.50 Mean :7.50 Mean : 9.50
## 3rd Qu.:1.75 3rd Qu.:3.75 3rd Qu.:10.25 3rd Qu.:7.75 3rd Qu.: 9.75
## Max. :2.00 Max. :4.00 Max. :12.00 Max. :8.00 Max. :10.00
a2 <- 1
#2a <- 1
c <- 1
c
## [1] 1
c(1,2)
## [1] 1 2
#else <- 1
c(1, 2, 3, 4)
## [1] 1 2 3 4
-2 < -2
## [1] FALSE
letters[1:3]
## [1] "a" "b" "c"
mode(x)
## [1] "numeric"
as.character(x)
## [1] "10" "9" "8" "12" "6" "5" "4" "3" "2" "1"
x
## [1] 10 9 8 12 6 5 4 3 2 1
x[c(TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE,FALSE, TRUE, FALSE)]
## [1] 10 8 6 4 2
x>5
## [1] TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE
x[x>5]
## [1] 10 9 8 12 6
length(x>5)
## [1] 10
length(x)
## [1] 10
x[x==3] # == : test for equality
## [1] 3
x[x!=3] # != : test for inequality
## [1] 10 9 8 12 6 5 4 2 1
x %in% c(3,8) # %in%: test which values are part of a set of specified values
## [1] FALSE FALSE TRUE FALSE FALSE FALSE FALSE TRUE FALSE FALSE
x[x %in% c(3,8)]
## [1] 8 3
x[x=3] # = : assignment operator
## [1] 8
sum(x>3)
## [1] 7
TRUE & FALSE
## [1] FALSE
TRUE | FALSE
## [1] TRUE
x
## [1] 10 9 8 12 6 5 4 3 2 1
x>5
## [1] TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE
x<8
## [1] FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE
x>5 & x<8
## [1] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE
sum(x>5 & x<8)
## [1] 1
x[x>5 & x<8]
## [1] 6
m <- c(1,2,3,4)
names(m) <- c("gene1","gene2","gene3","gene4")
m
## gene1 gene2 gene3 gene4
## 1 2 3 4
rownames(A)
## NULL
rownames(A) <- c("gene1", "gene2")
colnames(A) <- c("sample1", "sample2", "sample3","sample4", "sample5")
A
## sample1 sample2 sample3 sample4 sample5
## gene1 1 3 5 7 9
## gene2 2 4 12 8 10
m["gene3"]
## gene3
## 3
A["gene1", ]
## sample1 sample2 sample3 sample4 sample5
## 1 3 5 7 9
c("gene1", 5)
## [1] "gene1" "5"
list(gene = "gene1", number = 5)
## $gene
## [1] "gene1"
##
## $number
## [1] 5
x <- list(gene = "gene1", number = 5)
x[1]
## $gene
## [1] "gene1"
x[[1]]
## [1] "gene1"
x$gene
## [1] "gene1"
pclass <- c("1st","2nd","1st")
survived <- c(1,1,0)
name <- c("Elisabeth Walton","Hudson Trevor","Helen Loraine")
age <- c(29.0,0.9167,2.0)
titanic <- data.frame(pclass,survived,name,age)
titanic
## pclass survived name age
## 1 1st 1 Elisabeth Walton 29.0000
## 2 2nd 1 Hudson Trevor 0.9167
## 3 1st 0 Helen Loraine 2.0000
titanic[c(2,3),]
## pclass survived name age
## 2 2nd 1 Hudson Trevor 0.9167
## 3 1st 0 Helen Loraine 2.0000
titanic[,c("name","age")]
## name age
## 1 Elisabeth Walton 29.0000
## 2 Hudson Trevor 0.9167
## 3 Helen Loraine 2.0000
titanic[c(2,3),c("name","age")]
## name age
## 2 Hudson Trevor 0.9167
## 3 Helen Loraine 2.0000
titanic$age
## [1] 29.0000 0.9167 2.0000
titanic[["age"]]
## [1] 29.0000 0.9167 2.0000
# You can also add a new variable to a data frame
titanic$status <- c("yes","yes","no")
titanic
## pclass survived name age status
## 1 1st 1 Elisabeth Walton 29.0000 yes
## 2 2nd 1 Hudson Trevor 0.9167 yes
## 3 1st 0 Helen Loraine 2.0000 no
In the exercises, we use the Titanic data set. See here for a description of the data.
library(foreign)
# First download file from course website and then import
#titanic3 <- read.dta("titanic3.dta", convert.underscore=TRUE) # convert.underscore: Convert "_" in Stata variable names to "." in R names?
titanic3 <- read.dta("Exercises/titanic3.dta", convert.underscore=TRUE)
dim(titanic3)
## [1] 1309 17
head(titanic3[,1:4])
## pclass survived name sex
## 1 1st 1 Allen, Miss. Elisabeth Walton female
## 2 1st 1 Allison, Master. Hudson Trevor male
## 3 1st 0 Allison, Miss. Helen Loraine female
## 4 1st 0 Allison, Mr. Hudson Joshua Crei male
## 5 1st 0 Allison, Mrs. Hudson J C (Bessi female
## 6 1st 1 Anderson, Mr. Harry male
tail(titanic3[,1:4])
## pclass survived name sex
## 1304 3rd 0 Yousseff, Mr. Gerious male
## 1305 3rd 0 Zabour, Miss. Hileni female
## 1306 3rd 0 Zabour, Miss. Thamine female
## 1307 3rd 0 Zakarian, Mr. Mapriededer male
## 1308 3rd 0 Zakarian, Mr. Ortin male
## 1309 3rd 0 Zimmerman, Mr. Leo male
str(titanic3[,1:4])
## 'data.frame': 1309 obs. of 4 variables:
## $ pclass : Factor w/ 3 levels "1st","2nd","3rd": 1 1 1 1 1 1 1 1 1 1 ...
## $ survived: int 1 1 0 0 0 1 1 0 1 0 ...
## $ name : chr "Allen, Miss. Elisabeth Walton" "Allison, Master. Hudson Trevor" "Allison, Miss. Helen Loraine" "Allison, Mr. Hudson Joshua Crei" ...
## $ sex : Factor w/ 2 levels "female","male": 1 2 1 2 1 2 1 2 1 2 ...
#In R, we can also import directly from a web site:
#{r "Basic data import/export from other formats (I)"} #load(url("https://hbiostat.org/data/repo/titanic.sav")) #ls() #
An example using the readxl package for MS Excel files. The data set can be obtained from here and from the course website. If the data set has been stored in a subfolder Exercises, it can be imported via
install.packages("readxl")
## package 'readxl' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\pdmoerland\AppData\Local\Temp\RtmpURMFjN\downloaded_packages
library(readxl)
titanic3 <- read_excel("Exercises/titanic3.xls")
## Explain warning message and repair by converting to number
## tibble
dim(titanic3)
## [1] 1309 14
head(titanic3[,1:4])
## # A tibble: 6 x 4
## pclass survived name sex
## <dbl> <dbl> <chr> <chr>
## 1 1 1 Allen, Miss. Elisabeth Walton female
## 2 1 1 Allison, Master. Hudson Trevor male
## 3 1 0 Allison, Miss. Helen Loraine female
## 4 1 0 Allison, Mr. Hudson Joshua Creighton male
## 5 1 0 Allison, Mrs. Hudson J C (Bessie Waldo Daniels) female
## 6 1 1 Anderson, Mr. Harry male
tail(titanic3[,1:4])
## # A tibble: 6 x 4
## pclass survived name sex
## <dbl> <dbl> <chr> <chr>
## 1 3 0 Yousseff, Mr. Gerious male
## 2 3 0 Zabour, Miss. Hileni female
## 3 3 0 Zabour, Miss. Thamine female
## 4 3 0 Zakarian, Mr. Mapriededer male
## 5 3 0 Zakarian, Mr. Ortin male
## 6 3 0 Zimmerman, Mr. Leo male
We run the code to import the STATA file, which is what we will do in the exercises as well.
library(foreign)
titanic3 <- read.dta("Exercises/titanic3.dta", convert.underscore=TRUE)
Using the logarithm as an example, we show the different ways to obtain the 10-log of 100 (which should give 2 as outcome).
## Basic structure
log(100) # does not give 2
## [1] 4.60517
help(log)
log(100, 10)
## [1] 2
log(10, 100) # does not give 2
## [1] 0.5
log(base=10, x=100)
## [1] 2
log(b=10,x=100)
## [1] 2
## Some functions have an ... argument
c
## [1] 1
c(3,6,8)
## [1] 3 6 8
paste
## function (..., sep = " ", collapse = NULL, recycle0 = FALSE)
## .Internal(paste(list(...), sep, collapse, recycle0))
## <bytecode: 0x0000000006427c18>
## <environment: namespace:base>
help(paste)
paste("Academic","Medical","Center")
## [1] "Academic Medical Center"
## Some functions have an alias that is closer to common use
## E.g. + is an alias for the "+" function
"+"(1,7)
## [1] 8
## To cite R in publications:
citation()
## To cite R in publications use:
##
## R Core Team (2023). _R: A Language and Environment for Statistical
## Computing_. R Foundation for Statistical Computing, Vienna, Austria.
## <https://www.R-project.org/>.
##
## A BibTeX entry for LaTeX users is
##
## @Manual{,
## title = {R: A Language and Environment for Statistical Computing},
## author = {{R Core Team}},
## organization = {R Foundation for Statistical Computing},
## address = {Vienna, Austria},
## year = {2023},
## url = {https://www.R-project.org/},
## }
##
## We have invested a lot of time and effort in creating R, please cite it
## when using it for data analysis. See also 'citation("pkgname")' for
## citing R packages.
We can see the contents of a function by leaving out the parentheses. And we can write our own functions.
help
## function (topic, package = NULL, lib.loc = NULL, verbose = getOption("verbose"),
## try.all.packages = getOption("help.try.all.packages"), help_type = getOption("help_type"))
## {
## types <- c("text", "html", "pdf")
## help_type <- if (!length(help_type))
## "text"
## else match.arg(tolower(help_type), types)
## if (!missing(package))
## if (is.name(y <- substitute(package)))
## package <- as.character(y)
## if (missing(topic)) {
## if (!is.null(package)) {
## if (interactive() && help_type == "html") {
## port <- tools::startDynamicHelp(NA)
## if (port <= 0L)
## return(library(help = package, lib.loc = lib.loc,
## character.only = TRUE))
## browser <- if (.Platform$GUI == "AQUA") {
## get("aqua.browser", envir = as.environment("tools:RGUI"))
## }
## else getOption("browser")
## browseURL(paste0("http://127.0.0.1:", port, "/library/",
## package, "/html/00Index.html"), browser)
## return(invisible())
## }
## else return(library(help = package, lib.loc = lib.loc,
## character.only = TRUE))
## }
## if (!is.null(lib.loc))
## return(library(lib.loc = lib.loc))
## topic <- "help"
## package <- "utils"
## lib.loc <- .Library
## }
## ischar <- tryCatch(is.character(topic) && length(topic) ==
## 1L, error = function(e) FALSE)
## if (!ischar) {
## reserved <- c("TRUE", "FALSE", "NULL", "Inf", "NaN",
## "NA", "NA_integer_", "NA_real_", "NA_complex_", "NA_character_")
## stopic <- deparse1(substitute(topic))
## if (!is.name(substitute(topic)) && !stopic %in% reserved)
## stop("'topic' should be a name, length-one character vector or reserved word")
## topic <- stopic
## }
## paths <- index.search(topic, find.package(if (is.null(package))
## loadedNamespaces()
## else package, lib.loc, verbose = verbose))
## try.all.packages <- !length(paths) && is.logical(try.all.packages) &&
## !is.na(try.all.packages) && try.all.packages && is.null(package) &&
## is.null(lib.loc)
## if (try.all.packages) {
## for (lib in .libPaths()) {
## packages <- .packages(TRUE, lib)
## packages <- packages[is.na(match(packages, .packages()))]
## paths <- c(paths, index.search(topic, file.path(lib,
## packages)))
## }
## paths <- paths[nzchar(paths)]
## }
## structure(unique(paths), call = match.call(), topic = topic,
## tried_all_packages = try.all.packages, type = help_type,
## class = "help_files_with_topic")
## }
## <bytecode: 0x000000000918a888>
## <environment: namespace:utils>
good.morning <- function(work){
if(work==TRUE) cat("wake up") else
cat("you can stay in bed")
}
good.morning
## <srcref: file "" chars 1:17 to 4:1>
#good.morning()
good.morning(work=FALSE)
## you can stay in bed
install.packages("ISwR")
## package 'ISwR' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\pdmoerland\AppData\Local\Temp\RtmpURMFjN\downloaded_packages
library(ISwR)
help(juul)
summary(juul)
## age menarche sex igf1
## Min. : 0.170 Min. :1.000 Min. :1.000 Min. : 25.0
## 1st Qu.: 9.053 1st Qu.:1.000 1st Qu.:1.000 1st Qu.:202.2
## Median :12.560 Median :1.000 Median :2.000 Median :313.5
## Mean :15.095 Mean :1.476 Mean :1.534 Mean :340.2
## 3rd Qu.:16.855 3rd Qu.:2.000 3rd Qu.:2.000 3rd Qu.:462.8
## Max. :83.000 Max. :2.000 Max. :2.000 Max. :915.0
## NA's :5 NA's :635 NA's :5 NA's :321
## tanner testvol
## Min. :1.00 Min. : 1.000
## 1st Qu.:1.00 1st Qu.: 1.000
## Median :2.00 Median : 3.000
## Mean :2.64 Mean : 7.896
## 3rd Qu.:5.00 3rd Qu.:15.000
## Max. :5.00 Max. :30.000
## NA's :240 NA's :859
juul$age[1:10]
## [1] NA NA NA NA NA 0.17 0.17 0.17 0.17 0.17
juul[1:10,"age"]
## [1] NA NA NA NA NA 0.17 0.17 0.17 0.17 0.17
## head and tail functions
tail(juul[, c("menarche","sex")])
## menarche sex
## 1334 2 2
## 1335 2 2
## 1336 2 2
## 1337 2 2
## 1338 2 2
## 1339 2 2
## in baby steps
tmp <- juul[, c("menarche","sex")] # all rows, two columns
tail(tmp) # last six rows
## menarche sex
## 1334 2 2
## 1335 2 2
## 1336 2 2
## 1337 2 2
## 1338 2 2
## 1339 2 2
## or
tail(juul)[, c("menarche","sex")]
## menarche sex
## 1334 2 2
## 1335 2 2
## 1336 2 2
## 1337 2 2
## 1338 2 2
## 1339 2 2
## in baby steps
tmp <- tail(juul) # last six rows, all columns
tmp[, c("menarche","sex")] # two columns
## menarche sex
## 1334 2 2
## 1335 2 2
## 1336 2 2
## 1337 2 2
## 1338 2 2
## 1339 2 2
## some selections using subset function
subset(juul, tanner==2 & age<10)
## age menarche sex igf1 tanner testvol
## 192 9.50 NA 1 NA 2 2
## 831 9.82 1 2 NA 2 NA
## 835 9.89 1 2 229 2 NA
subset(juul, tanner>=4 & age>45)
## age menarche sex igf1 tanner testvol
## 1325 47.37 2 2 144 5 NA
## 1326 48.01 2 2 154 5 NA
## 1329 51.07 2 2 187 5 NA
## 1334 58.95 2 2 218 5 NA
## 1335 60.99 2 2 226 5 NA
subset(juul, tanner %in% c(1,5) & (age==0.25|age>50))
## age menarche sex igf1 tanner testvol
## 13 0.25 NA 1 90 1 NA
## 14 0.25 NA 1 141 1 NA
## 628 0.25 NA 2 51 1 NA
## 1329 51.07 2 2 187 5 NA
## 1334 58.95 2 2 218 5 NA
## 1335 60.99 2 2 226 5 NA
with(juul, table(sex, tanner))
## tanner
## sex 1 2 3 4 5
## 1 291 55 34 41 124
## 2 224 48 38 40 204
xtabs(~sex+tanner, data=juul)
## tanner
## sex 1 2 3 4 5
## 1 291 55 34 41 124
## 2 224 48 38 40 204
xtabs(~sex+tanner, data=juul, subset=(menarche==1))
## tanner
## sex 1 2 3 4 5
## 2 221 43 32 14 2
## also select columns using subset function
subset(juul, tanner==2 & age<10, select=c(menarche,sex))
## menarche sex
## 192 NA 1
## 831 1 2
## 835 1 2
When checking for missingness, we need to use the is.na function.
titanic3$age[1:20]
## [1] 29.0000 0.9167 2.0000 30.0000 25.0000 48.0000 63.0000 39.0000 53.0000
## [10] 71.0000 47.0000 18.0000 24.0000 26.0000 80.0000 NA 24.0000 50.0000
## [19] 32.0000 36.0000
table(titanic3$age==NA)
## < table of extent 0 >
3==NA
## [1] NA
is.na(3)
## [1] FALSE
table(is.na(titanic3$age))
##
## FALSE TRUE
## 1046 263
## select those with missing igf1 value
subset(juul, tanner %in% c(1,5) & is.na(igf1) & (age<5|age>18))
## age menarche sex igf1 tanner testvol
## 630 2.64 1 2 NA 1 NA
## 1225 18.09 2 2 NA 5 NA
## 1239 18.44 2 2 NA 5 NA
#quantile(juul$age, prob=c(0.025,0.25,0.5,0.75,0.975)) # gives an error
quantile(juul$age, prob=c(0.025,0.25,0.5,0.75,0.975), na.rm=TRUE)
## 2.5% 25% 50% 75% 97.5%
## 2.88525 9.05250 12.56000 16.85500 51.48175
with(juul, table(sex, menarche))
## menarche
## sex 1 2
## 1 0 0
## 2 369 335
with(juul, table(sex, menarche, useNA="always"))
## menarche
## sex 1 2 <NA>
## 1 0 0 621
## 2 369 335 9
## <NA> 0 0 5
DiseaseState <- factor(c("Cancer", "Cancer", "Normal"))
DiseaseState
## [1] Cancer Cancer Normal
## Levels: Cancer Normal
str(DiseaseState)
## Factor w/ 2 levels "Cancer","Normal": 1 1 2
levels(DiseaseState)
## [1] "Cancer" "Normal"
typeof(DiseaseState) # the internal coding is via integers
## [1] "integer"
is.factor(DiseaseState)
## [1] TRUE
help(factor)
## change labels
factor(c("Cancer", "Cancer", "Normal"), labels=c("Dis","Norm"))
## [1] Dis Dis Norm
## Levels: Dis Norm
## change ordering of levels
DiseaseState2 <- factor(c("Cancer", "Cancer", "Normal"),levels=c("Normal","Cancer"))
table(DiseaseState)
## DiseaseState
## Cancer Normal
## 2 1
table(DiseaseState2)
## DiseaseState2
## Normal Cancer
## 1 2
## can also use relevel function
relevel(DiseaseState, ref="Normal")
## [1] Cancer Cancer Normal
## Levels: Normal Cancer
## see what changes internally
as.numeric(DiseaseState)
## [1] 1 1 2
as.numeric(relevel(DiseaseState, ref="Normal"))
## [1] 2 2 1
as.Date("15 April 1912", "%d %b %Y")
## [1] "1912-04-15"
julian(as.Date("15 April 1912", "%d %b %Y"))
## [1] -21080
## attr(,"origin")
## [1] "1970-01-01"
titanic3$dob <- as.Date("15 April 1912", "%d %b %Y")+ (-titanic3$age*365.25)
as.Date("15041912", "%d%m%Y")
## [1] "1912-04-15"
as.Date("150412", "%d%m%y")
## [1] "2012-04-15"
format(as.Date("1912April15", "%Y%b%d"),"%A %B %d, %Y")
## [1] "Monday April 15, 1912"
install.packages("lubridate")
##
## There is a binary version available but the source version is later:
## binary source needs_compilation
## lubridate 1.9.3 1.9.4 TRUE
##
## package 'timechange' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\pdmoerland\AppData\Local\Temp\RtmpURMFjN\downloaded_packages
library(lubridate)
wday(as.Date("1912April15", "%Y%b%d"),label=TRUE)
## [1] Mon
## Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat
#install.packages("swirl")
#library(swirl)
#install_from_swirl("R Programming")
#swirl()
x <- (0:100)/10
plot(x, x^3 - 13 * x^2 + 39 * x)
plot(x, x^3 - 13 * x^2 + 39 * x,cex.axis=1.5,cex.lab=1.5)
plot(x,x^3-13*x^2+39*x,type="l",xlab="time (hours)",ylab="temperature",main="Enhanced plot",cex.axis=1.5,cex.lab=1.5)
colors()
## [1] "white" "aliceblue" "antiquewhite"
## [4] "antiquewhite1" "antiquewhite2" "antiquewhite3"
## [7] "antiquewhite4" "aquamarine" "aquamarine1"
## [10] "aquamarine2" "aquamarine3" "aquamarine4"
## [13] "azure" "azure1" "azure2"
## [16] "azure3" "azure4" "beige"
## [19] "bisque" "bisque1" "bisque2"
## [22] "bisque3" "bisque4" "black"
## [25] "blanchedalmond" "blue" "blue1"
## [28] "blue2" "blue3" "blue4"
## [31] "blueviolet" "brown" "brown1"
## [34] "brown2" "brown3" "brown4"
## [37] "burlywood" "burlywood1" "burlywood2"
## [40] "burlywood3" "burlywood4" "cadetblue"
## [43] "cadetblue1" "cadetblue2" "cadetblue3"
## [46] "cadetblue4" "chartreuse" "chartreuse1"
## [49] "chartreuse2" "chartreuse3" "chartreuse4"
## [52] "chocolate" "chocolate1" "chocolate2"
## [55] "chocolate3" "chocolate4" "coral"
## [58] "coral1" "coral2" "coral3"
## [61] "coral4" "cornflowerblue" "cornsilk"
## [64] "cornsilk1" "cornsilk2" "cornsilk3"
## [67] "cornsilk4" "cyan" "cyan1"
## [70] "cyan2" "cyan3" "cyan4"
## [73] "darkblue" "darkcyan" "darkgoldenrod"
## [76] "darkgoldenrod1" "darkgoldenrod2" "darkgoldenrod3"
## [79] "darkgoldenrod4" "darkgray" "darkgreen"
## [82] "darkgrey" "darkkhaki" "darkmagenta"
## [85] "darkolivegreen" "darkolivegreen1" "darkolivegreen2"
## [88] "darkolivegreen3" "darkolivegreen4" "darkorange"
## [91] "darkorange1" "darkorange2" "darkorange3"
## [94] "darkorange4" "darkorchid" "darkorchid1"
## [97] "darkorchid2" "darkorchid3" "darkorchid4"
## [100] "darkred" "darksalmon" "darkseagreen"
## [103] "darkseagreen1" "darkseagreen2" "darkseagreen3"
## [106] "darkseagreen4" "darkslateblue" "darkslategray"
## [109] "darkslategray1" "darkslategray2" "darkslategray3"
## [112] "darkslategray4" "darkslategrey" "darkturquoise"
## [115] "darkviolet" "deeppink" "deeppink1"
## [118] "deeppink2" "deeppink3" "deeppink4"
## [121] "deepskyblue" "deepskyblue1" "deepskyblue2"
## [124] "deepskyblue3" "deepskyblue4" "dimgray"
## [127] "dimgrey" "dodgerblue" "dodgerblue1"
## [130] "dodgerblue2" "dodgerblue3" "dodgerblue4"
## [133] "firebrick" "firebrick1" "firebrick2"
## [136] "firebrick3" "firebrick4" "floralwhite"
## [139] "forestgreen" "gainsboro" "ghostwhite"
## [142] "gold" "gold1" "gold2"
## [145] "gold3" "gold4" "goldenrod"
## [148] "goldenrod1" "goldenrod2" "goldenrod3"
## [151] "goldenrod4" "gray" "gray0"
## [154] "gray1" "gray2" "gray3"
## [157] "gray4" "gray5" "gray6"
## [160] "gray7" "gray8" "gray9"
## [163] "gray10" "gray11" "gray12"
## [166] "gray13" "gray14" "gray15"
## [169] "gray16" "gray17" "gray18"
## [172] "gray19" "gray20" "gray21"
## [175] "gray22" "gray23" "gray24"
## [178] "gray25" "gray26" "gray27"
## [181] "gray28" "gray29" "gray30"
## [184] "gray31" "gray32" "gray33"
## [187] "gray34" "gray35" "gray36"
## [190] "gray37" "gray38" "gray39"
## [193] "gray40" "gray41" "gray42"
## [196] "gray43" "gray44" "gray45"
## [199] "gray46" "gray47" "gray48"
## [202] "gray49" "gray50" "gray51"
## [205] "gray52" "gray53" "gray54"
## [208] "gray55" "gray56" "gray57"
## [211] "gray58" "gray59" "gray60"
## [214] "gray61" "gray62" "gray63"
## [217] "gray64" "gray65" "gray66"
## [220] "gray67" "gray68" "gray69"
## [223] "gray70" "gray71" "gray72"
## [226] "gray73" "gray74" "gray75"
## [229] "gray76" "gray77" "gray78"
## [232] "gray79" "gray80" "gray81"
## [235] "gray82" "gray83" "gray84"
## [238] "gray85" "gray86" "gray87"
## [241] "gray88" "gray89" "gray90"
## [244] "gray91" "gray92" "gray93"
## [247] "gray94" "gray95" "gray96"
## [250] "gray97" "gray98" "gray99"
## [253] "gray100" "green" "green1"
## [256] "green2" "green3" "green4"
## [259] "greenyellow" "grey" "grey0"
## [262] "grey1" "grey2" "grey3"
## [265] "grey4" "grey5" "grey6"
## [268] "grey7" "grey8" "grey9"
## [271] "grey10" "grey11" "grey12"
## [274] "grey13" "grey14" "grey15"
## [277] "grey16" "grey17" "grey18"
## [280] "grey19" "grey20" "grey21"
## [283] "grey22" "grey23" "grey24"
## [286] "grey25" "grey26" "grey27"
## [289] "grey28" "grey29" "grey30"
## [292] "grey31" "grey32" "grey33"
## [295] "grey34" "grey35" "grey36"
## [298] "grey37" "grey38" "grey39"
## [301] "grey40" "grey41" "grey42"
## [304] "grey43" "grey44" "grey45"
## [307] "grey46" "grey47" "grey48"
## [310] "grey49" "grey50" "grey51"
## [313] "grey52" "grey53" "grey54"
## [316] "grey55" "grey56" "grey57"
## [319] "grey58" "grey59" "grey60"
## [322] "grey61" "grey62" "grey63"
## [325] "grey64" "grey65" "grey66"
## [328] "grey67" "grey68" "grey69"
## [331] "grey70" "grey71" "grey72"
## [334] "grey73" "grey74" "grey75"
## [337] "grey76" "grey77" "grey78"
## [340] "grey79" "grey80" "grey81"
## [343] "grey82" "grey83" "grey84"
## [346] "grey85" "grey86" "grey87"
## [349] "grey88" "grey89" "grey90"
## [352] "grey91" "grey92" "grey93"
## [355] "grey94" "grey95" "grey96"
## [358] "grey97" "grey98" "grey99"
## [361] "grey100" "honeydew" "honeydew1"
## [364] "honeydew2" "honeydew3" "honeydew4"
## [367] "hotpink" "hotpink1" "hotpink2"
## [370] "hotpink3" "hotpink4" "indianred"
## [373] "indianred1" "indianred2" "indianred3"
## [376] "indianred4" "ivory" "ivory1"
## [379] "ivory2" "ivory3" "ivory4"
## [382] "khaki" "khaki1" "khaki2"
## [385] "khaki3" "khaki4" "lavender"
## [388] "lavenderblush" "lavenderblush1" "lavenderblush2"
## [391] "lavenderblush3" "lavenderblush4" "lawngreen"
## [394] "lemonchiffon" "lemonchiffon1" "lemonchiffon2"
## [397] "lemonchiffon3" "lemonchiffon4" "lightblue"
## [400] "lightblue1" "lightblue2" "lightblue3"
## [403] "lightblue4" "lightcoral" "lightcyan"
## [406] "lightcyan1" "lightcyan2" "lightcyan3"
## [409] "lightcyan4" "lightgoldenrod" "lightgoldenrod1"
## [412] "lightgoldenrod2" "lightgoldenrod3" "lightgoldenrod4"
## [415] "lightgoldenrodyellow" "lightgray" "lightgreen"
## [418] "lightgrey" "lightpink" "lightpink1"
## [421] "lightpink2" "lightpink3" "lightpink4"
## [424] "lightsalmon" "lightsalmon1" "lightsalmon2"
## [427] "lightsalmon3" "lightsalmon4" "lightseagreen"
## [430] "lightskyblue" "lightskyblue1" "lightskyblue2"
## [433] "lightskyblue3" "lightskyblue4" "lightslateblue"
## [436] "lightslategray" "lightslategrey" "lightsteelblue"
## [439] "lightsteelblue1" "lightsteelblue2" "lightsteelblue3"
## [442] "lightsteelblue4" "lightyellow" "lightyellow1"
## [445] "lightyellow2" "lightyellow3" "lightyellow4"
## [448] "limegreen" "linen" "magenta"
## [451] "magenta1" "magenta2" "magenta3"
## [454] "magenta4" "maroon" "maroon1"
## [457] "maroon2" "maroon3" "maroon4"
## [460] "mediumaquamarine" "mediumblue" "mediumorchid"
## [463] "mediumorchid1" "mediumorchid2" "mediumorchid3"
## [466] "mediumorchid4" "mediumpurple" "mediumpurple1"
## [469] "mediumpurple2" "mediumpurple3" "mediumpurple4"
## [472] "mediumseagreen" "mediumslateblue" "mediumspringgreen"
## [475] "mediumturquoise" "mediumvioletred" "midnightblue"
## [478] "mintcream" "mistyrose" "mistyrose1"
## [481] "mistyrose2" "mistyrose3" "mistyrose4"
## [484] "moccasin" "navajowhite" "navajowhite1"
## [487] "navajowhite2" "navajowhite3" "navajowhite4"
## [490] "navy" "navyblue" "oldlace"
## [493] "olivedrab" "olivedrab1" "olivedrab2"
## [496] "olivedrab3" "olivedrab4" "orange"
## [499] "orange1" "orange2" "orange3"
## [502] "orange4" "orangered" "orangered1"
## [505] "orangered2" "orangered3" "orangered4"
## [508] "orchid" "orchid1" "orchid2"
## [511] "orchid3" "orchid4" "palegoldenrod"
## [514] "palegreen" "palegreen1" "palegreen2"
## [517] "palegreen3" "palegreen4" "paleturquoise"
## [520] "paleturquoise1" "paleturquoise2" "paleturquoise3"
## [523] "paleturquoise4" "palevioletred" "palevioletred1"
## [526] "palevioletred2" "palevioletred3" "palevioletred4"
## [529] "papayawhip" "peachpuff" "peachpuff1"
## [532] "peachpuff2" "peachpuff3" "peachpuff4"
## [535] "peru" "pink" "pink1"
## [538] "pink2" "pink3" "pink4"
## [541] "plum" "plum1" "plum2"
## [544] "plum3" "plum4" "powderblue"
## [547] "purple" "purple1" "purple2"
## [550] "purple3" "purple4" "red"
## [553] "red1" "red2" "red3"
## [556] "red4" "rosybrown" "rosybrown1"
## [559] "rosybrown2" "rosybrown3" "rosybrown4"
## [562] "royalblue" "royalblue1" "royalblue2"
## [565] "royalblue3" "royalblue4" "saddlebrown"
## [568] "salmon" "salmon1" "salmon2"
## [571] "salmon3" "salmon4" "sandybrown"
## [574] "seagreen" "seagreen1" "seagreen2"
## [577] "seagreen3" "seagreen4" "seashell"
## [580] "seashell1" "seashell2" "seashell3"
## [583] "seashell4" "sienna" "sienna1"
## [586] "sienna2" "sienna3" "sienna4"
## [589] "skyblue" "skyblue1" "skyblue2"
## [592] "skyblue3" "skyblue4" "slateblue"
## [595] "slateblue1" "slateblue2" "slateblue3"
## [598] "slateblue4" "slategray" "slategray1"
## [601] "slategray2" "slategray3" "slategray4"
## [604] "slategrey" "snow" "snow1"
## [607] "snow2" "snow3" "snow4"
## [610] "springgreen" "springgreen1" "springgreen2"
## [613] "springgreen3" "springgreen4" "steelblue"
## [616] "steelblue1" "steelblue2" "steelblue3"
## [619] "steelblue4" "tan" "tan1"
## [622] "tan2" "tan3" "tan4"
## [625] "thistle" "thistle1" "thistle2"
## [628] "thistle3" "thistle4" "tomato"
## [631] "tomato1" "tomato2" "tomato3"
## [634] "tomato4" "turquoise" "turquoise1"
## [637] "turquoise2" "turquoise3" "turquoise4"
## [640] "violet" "violetred" "violetred1"
## [643] "violetred2" "violetred3" "violetred4"
## [646] "wheat" "wheat1" "wheat2"
## [649] "wheat3" "wheat4" "whitesmoke"
## [652] "yellow" "yellow1" "yellow2"
## [655] "yellow3" "yellow4" "yellowgreen"
plot(x,x^3-13*x^2+39*x,pch=18,xlab="time (hours)",ylab="temperature",col="red",main="Enhanced plot",cex.axis=1.5,cex.lab=1.5)
palette()
## [1] "black" "#DF536B" "#61D04F" "#2297E6" "#28E2E5" "#CD0BBC" "#F5C710"
## [8] "gray62"
plot(x,x^3-13*x^2+39*x,pch=18,xlab="time (hours)",ylab="temperature",col=3,main="Enhanced plot",cex.axis=1.5,cex.lab=1.5)
plot(1:25, pch=1:25,cex=2,bg="grey")
x<-(0:100)/10
plot(x,x^3-13*x^2+39*x,type="l",xlab="time (hours)",ylab="temperature",cex.axis=1.5,cex.lab=1.5)
points(2,34,col="red",pch=16,cex=2)
arrows(4,50,2.2,34.5)
text(4.15,50,"local maximum",adj=0,col="blue",cex=1.5)
lines(x,30-50*sin(x/2),col="blue")
legend(x=0,y=80,legend=c("Sahara","Gobi"),lty=1,col=c("black","blue"),cex=1.5)
?par
par("bg")
## [1] "white"
par(bg="green")
par("bg")
## [1] "green"
# rerun the plot commands
x<-(0:100)/10
plot(x,x^3-13*x^2+39*x,type="l",xlab="time (hours)",ylab="temperature",cex.axis=1.5,cex.lab=1.5)
points(2,34,col="red",pch=16,cex=2)
arrows(4,50,2.2,34.5)
text(4.15,50,"local maximum",adj=0,col="blue",cex=1.5)
lines(x,30-50*sin(x/2),col="blue")
legend(x=0,y=80,legend=c("Sahara","Gobi"),lty=1,col=c("black","blue"),cex=1.5)
plot(1:10)
par(bg="white")
plot(1:10)
# save default graphical parameters to be able to restore them later on
par.defaults <- par(no.readonly=TRUE)
par(bg="green")
par("bg")
## [1] "green"
plot(1:10)
par(par.defaults)
par("bg")
## [1] "white"
plot(1:10)
x<-(0:100)/10
plot(x,x^3-13*x^2+39*x,type="l",xlab= "time (hours)",ylab="temperature",lwd=3,las=1,cex.axis=1.5,cex.lab=1.5)
hist(titanic3$age,breaks=15,freq=FALSE,cex.axis=1.5,cex.lab=1.5)
boxplot(titanic3$fare,ylim=c(0,300),ylab="fare",cex.axis=1.5,cex.lab=1.5)
boxplot(fare ~ pclass,data=titanic3,ylim=c(0,300),ylab="fare",cex.axis=1.5,cex.lab=1.5)
plot(fare ~ pclass,data=titanic3,ylim=c(0,300),ylab="fare",cex.axis=1.5,cex.lab=1.5)
# graphics
plot(fare~age,data=titanic3) # very skewed distribution
plot(log10(fare)~age,data=titanic3) # plot log10(y) vs x
plot(fare~age,data=titanic3,log="y") # original data, but log scale
min(titanic3$fare,na.rm=TRUE) # zero values!
## [1] 0
sum(titanic3$fare==0,na.rm=TRUE) # zero values!
## [1] 17
install.packages("ggplot2")
## package 'ggplot2' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\pdmoerland\AppData\Local\Temp\RtmpURMFjN\downloaded_packages
library(ggplot2)
qplot(age,fare,data=titanic3)
qplot(age,fare,data=titanic3) + scale_y_log10() # log scale for y values
qplot(age,fare,data=titanic3,facets=~pclass) # one plot per pclass
qplot(age,fare,data=titanic3,facets=~pclass,ylim=c(0,280)) # better for comparison
qplot(age,fare,data=titanic3,facets=sex~pclass) + scale_y_log10() # even better
qplot(age,fare,data=titanic3,facets=pclass~sex) + scale_y_log10() # better for comparing males and females per class
#install.packages("devtools")
#library(devtools)
#install_github("rCharts", "ramnathv", ref = "dev")
#library(rCharts)
#titanic3$survived = factor(titanic3$survived, labels=c("no","yes"))
#rPlot(fare ~ age| sex + pclass, data = titanic3, type = "point", color = "survived", size = list(const = 2))
#dt <- dTable(titanic3,sPaginationType= "full_numbers")
#dt
## Open the PDF device
pdf("titanic3_ggplot_v1.pdf")
qplot(age,fare,data=titanic3,facets=pclass~sex) + scale_y_log10()
## Close the device again to save the file
dev.off()
## png
## 2
qplot(age,fare,data=titanic3,facets=pclass~sex) + scale_y_log10()
dev.print("titanic3_ggplot_v2.pdf",device=pdf)
## png
## 2
## Change size, for pdf device width and height are specified in inches
pdf("titanic3_ggplot_v1_big.pdf", width=21, height=21)
qplot(age,fare,data=titanic3,facets=pclass~sex) + scale_y_log10()
## Close the device again to save the file
dev.off()
## png
## 2
search()
## [1] ".GlobalEnv" "package:ggplot2" "package:lubridate"
## [4] "package:ISwR" "package:readxl" "package:foreign"
## [7] "package:stats" "package:graphics" "package:grDevices"
## [10] "package:utils" "package:datasets" "package:methods"
## [13] "Autoloads" "package:base"
ls() # objects in Workspace
## [1] "A" "a2" "age" "c"
## [5] "DiseaseState" "DiseaseState2" "good.morning" "indx"
## [9] "m" "name" "par.defaults" "pclass"
## [13] "r" "survived" "titanic" "titanic3"
## [17] "tmp" "x"
ls("package:stats")[1:20] # some objects in stats package
## [1] "acf" "acf2AR" "add.scope"
## [4] "add1" "addmargins" "aggregate"
## [7] "aggregate.data.frame" "aggregate.ts" "AIC"
## [10] "alias" "anova" "ansari.test"
## [13] "aov" "approx" "approxfun"
## [16] "ar" "ar.burg" "ar.mle"
## [19] "ar.ols" "ar.yw"
ls("package:base")[1:30] # some objects in base package
## [1] "-" "-.Date" "-.POSIXt"
## [4] "!" "!.hexmode" "!.octmode"
## [7] "!=" "$" "$.DLLInfo"
## [10] "$.package_version" "$<-" "$<-.data.frame"
## [13] "$<-.POSIXlt" "%%" "%*%"
## [16] "%/%" "%in%" "%o%"
## [19] "%x%" "&" "&&"
## [22] "&.hexmode" "&.octmode" "("
## [25] "*" "*.difftime" "/"
## [28] "/.difftime" ":" "::"
## Hierarchical structure and duplicate names
data(quakes) # from package:datasets
## New quakes object in Workspace hides the other
quakes <- 1:10
quakes
## [1] 1 2 3 4 5 6 7 8 9 10
## Removing it makes the other visible again
rm(quakes)
quakes$mag # original quakes not overwritten!
## [1] 4.8 4.2 5.4 4.1 4.0 4.0 4.8 4.4 4.7 4.3 4.4 4.6 4.4 4.4 6.1 4.3 6.0 4.5
## [19] 4.4 4.4 4.5 4.2 4.4 4.7 5.4 4.0 4.6 5.2 4.5 4.4 4.6 4.7 4.8 4.0 4.5 4.3
## [37] 4.5 4.6 4.1 4.4 4.7 4.6 4.4 4.3 4.6 4.9 4.5 4.4 4.3 5.1 4.2 4.0 4.6 4.3
## [55] 4.2 4.4 4.5 4.0 4.4 4.3 4.7 4.1 5.0 4.6 4.9 4.7 4.1 5.0 4.5 5.5 4.0 4.5
## [73] 4.3 5.2 4.4 4.3 4.1 4.5 4.2 5.3 5.2 4.5 4.6 4.3 4.0 4.3 4.7 4.5 4.2 4.3
## [91] 5.1 4.7 5.2 4.2 4.2 4.0 4.5 5.2 5.1 4.7 4.1 4.6 4.7 4.7 4.6 4.2 4.4 4.6
## [109] 5.7 5.0 4.5 4.2 4.0 4.8 4.4 4.2 5.3 4.7 4.8 4.2 4.8 4.3 4.7 4.5 4.4 5.1
## [127] 4.2 5.0 4.8 4.3 4.5 4.2 4.5 4.6 4.3 4.7 5.1 4.6 4.9 4.2 4.6 4.0 5.0 4.4
## [145] 4.2 4.2 4.4 4.9 5.3 4.0 5.7 6.4 4.3 4.2 4.7 4.7 4.2 4.3 4.9 4.6 4.1 4.8
## [163] 4.6 4.6 4.8 5.0 5.6 5.3 4.7 4.5 4.3 4.6 4.1 4.1 4.1 5.7 5.0 4.5 4.1 4.6
## [181] 4.5 4.3 4.4 4.2 4.1 4.9 4.3 4.9 4.6 4.6 5.3 4.7 4.6 4.1 4.6 4.2 4.6 4.5
## [199] 4.3 5.2 4.3 4.0 4.7 4.5 4.5 4.3 5.2 4.5 4.7 4.2 4.7 4.3 4.1 5.4 4.3 4.3
## [217] 4.2 4.6 4.4 4.2 4.7 4.6 4.9 4.2 4.5 4.9 4.2 4.5 5.0 5.0 4.7 4.3 4.4 4.9
## [235] 4.5 4.0 4.4 5.0 4.7 4.8 4.5 4.1 5.3 4.8 5.0 4.6 4.3 4.7 5.3 4.2 4.7 4.5
## [253] 5.1 4.9 4.4 4.2 4.6 4.7 4.2 4.9 5.1 4.7 4.4 4.4 4.2 4.9 4.6 4.4 4.6 4.5
## [271] 4.4 4.9 4.1 4.2 5.7 4.6 5.0 4.3 4.5 5.2 4.4 4.2 4.6 4.0 4.4 4.7 4.2 4.7
## [289] 4.5 5.0 5.0 4.8 4.6 4.6 5.0 5.0 5.6 4.0 4.0 4.6 4.4 4.8 4.7 4.6 4.3 4.7
## [307] 4.1 4.9 4.6 4.8 4.9 5.1 5.4 4.5 4.9 4.4 4.1 5.3 4.5 4.9 4.8 5.2 4.4 4.4
## [325] 4.9 4.4 4.2 4.6 4.6 5.3 5.3 4.5 4.4 5.0 5.1 4.5 4.5 5.4 4.5 4.7 4.2 4.8
## [343] 4.5 4.3 4.3 4.3 4.6 4.5 5.0 4.6 4.6 4.9 4.1 5.5 4.7 5.0 5.1 5.5 4.6 4.7
## [361] 4.2 4.0 5.4 4.3 4.4 4.6 5.1 4.5 4.2 4.1 5.1 5.4 5.1 5.1 4.4 5.7 4.4 5.1
## [379] 4.6 5.5 5.1 4.4 5.0 5.0 5.1 5.1 4.2 4.5 4.0 4.9 4.3 4.8 4.4 4.2 4.9 4.2
## [397] 5.3 5.0 5.7 5.3 4.7 4.6 4.3 5.4 4.4 4.3 4.3 4.7 4.4 4.2 4.5 4.8 4.8 4.3
## [415] 4.4 5.1 4.4 4.4 4.3 4.8 4.3 4.5 4.1 5.1 4.7 4.6 4.7 4.6 4.4 4.2 4.1 4.7
## [433] 4.0 4.8 4.4 4.3 4.4 4.5 4.5 4.7 4.3 4.7 4.8 4.6 5.1 4.7 4.3 5.1 5.5 4.5
## [451] 4.3 4.3 4.7 4.3 4.3 4.6 4.5 4.5 5.4 4.6 4.4 5.0 5.2 4.4 5.1 4.4 4.4 4.8
## [469] 4.4 4.7 4.7 4.4 4.3 5.0 4.5 4.6 5.4 4.6 4.5 4.4 4.5 4.1 4.0 4.9 4.1 5.2
## [487] 4.4 4.1 4.9 4.6 4.5 4.8 4.2 4.2 4.1 5.5 4.4 4.8 4.2 4.8 4.9 4.6 4.5 4.4
## [505] 4.6 4.2 4.7 4.4 4.5 4.9 4.7 5.5 4.7 4.6 4.1 4.7 4.6 4.3 4.4 4.7 4.3 4.1
## [523] 4.7 4.5 5.5 4.5 4.6 5.1 4.4 4.7 5.5 4.6 4.0 4.6 4.8 4.7 4.7 4.2 5.4 4.6
## [541] 5.5 4.2 4.5 4.5 4.8 4.6 5.4 4.6 5.0 4.3 4.3 4.8 4.7 4.7 4.8 4.2 4.2 5.9
## [559] 4.6 4.5 4.9 4.7 4.9 5.3 4.2 4.2 4.5 5.2 4.5 5.6 5.2 4.8 4.5 5.0 4.4 4.5
## [577] 4.6 4.5 5.2 5.1 4.8 4.3 5.1 4.7 4.6 4.8 4.6 4.4 4.6 5.1 4.3 4.4 4.7 4.8
## [595] 4.1 4.6 4.9 4.0 4.7 4.7 5.2 4.6 4.6 4.9 5.7 4.7 4.4 4.9 4.8 4.6 4.4 4.8
## [613] 4.7 4.2 5.1 4.8 4.9 5.1 4.3 4.4 4.7 4.7 5.3 5.1 4.9 4.5 4.7 4.2 5.1 4.8
## [631] 4.2 4.8 4.4 4.5 4.3 5.6 4.0 5.0 4.2 4.6 4.6 4.5 5.0 4.7 4.6 4.8 4.6 4.4
## [649] 5.6 4.2 5.4 4.8 5.6 4.4 4.7 4.6 5.1 4.6 4.5 4.2 4.8 4.9 5.5 5.0 4.2 5.2
## [667] 4.8 4.4 4.8 4.4 4.1 4.9 4.6 4.5 5.3 4.8 4.6 4.8 4.7 4.9 5.3 4.4 4.6 4.3
## [685] 4.4 4.2 4.1 4.2 5.0 4.1 4.3 5.2 4.2 4.5 4.4 4.4 5.0 4.0 4.8 5.0 4.2 5.2
## [703] 5.2 4.5 4.3 4.5 4.6 5.1 4.4 4.3 4.7 5.6 4.9 5.1 4.6 4.4 4.8 4.2 4.7 4.1
## [721] 4.7 4.0 4.9 5.0 4.5 4.4 4.0 4.5 4.7 4.4 4.7 4.7 4.0 4.2 4.5 4.7 4.5 4.1
## [739] 4.6 4.3 4.6 5.2 4.6 4.7 5.0 5.2 4.4 4.6 4.5 4.0 4.2 5.3 5.9 4.9 4.5 4.4
## [757] 5.4 5.3 5.1 4.1 4.3 4.5 4.1 5.1 5.3 4.5 4.1 4.4 4.7 4.0 5.1 4.0 4.3 4.3
## [775] 4.0 4.1 4.4 4.3 4.2 4.0 4.5 4.7 5.0 4.3 5.1 4.7 5.3 5.0 4.5 5.0 4.1 4.9
## [793] 4.1 4.0 4.4 4.5 4.4 4.5 4.3 4.3 5.0 4.5 4.5 4.4 4.5 4.1 4.9 4.7 4.3 4.6
## [811] 4.6 5.2 4.5 4.3 4.6 4.0 4.5 4.8 4.6 4.1 4.9 4.7 4.1 4.3 4.4 4.0 4.8 4.4
## [829] 4.4 4.6 4.2 4.1 4.2 4.0 4.1 4.1 4.7 4.8 5.1 5.0 4.8 4.4 5.0 5.2 4.2 4.1
## [847] 4.8 4.5 5.0 5.1 4.1 4.7 5.2 4.8 4.5 4.0 4.7 4.1 4.3 4.3 4.0 4.7 4.1 4.2
## [865] 4.8 4.8 4.2 4.2 5.7 6.0 4.2 4.5 4.9 4.4 4.0 4.3 4.2 4.5 4.8 4.4 4.2 4.2
## [883] 5.0 4.2 5.2 4.5 4.6 5.0 5.0 5.4 4.8 4.2 5.5 4.3 4.1 4.4 4.9 4.5 4.9 4.0
## [901] 4.5 5.0 4.9 4.5 4.2 4.2 4.2 5.2 4.3 5.1 4.6 4.6 4.4 4.4 4.9 5.1 4.2 4.7
## [919] 4.0 5.6 5.3 5.0 4.3 4.1 5.1 4.5 4.9 5.4 4.7 4.8 4.5 4.2 4.6 4.6 5.6 5.4
## [937] 4.0 5.2 4.2 4.7 4.3 4.8 4.6 5.4 4.8 4.6 4.2 5.5 4.7 4.7 4.5 5.5 4.5 4.1
## [955] 4.0 4.3 4.7 4.9 4.5 4.7 4.5 4.8 4.3 4.1 5.4 4.1 4.8 4.2 4.8 5.4 4.4 5.2
## [973] 4.7 4.9 4.9 4.2 4.4 4.4 4.3 4.9 5.0 4.7 4.9 4.3 4.5 4.2 5.2 4.8 4.0 4.7
## [991] 4.3 4.3 4.9 4.0 4.2 4.4 4.7 4.5 4.5 6.0
find("quakes")
## [1] "package:datasets"
datasets::quakes
## lat long depth mag stations
## 1 -20.42 181.62 562 4.8 41
## 2 -20.62 181.03 650 4.2 15
## 3 -26.00 184.10 42 5.4 43
## 4 -17.97 181.66 626 4.1 19
## 5 -20.42 181.96 649 4.0 11
## 6 -19.68 184.31 195 4.0 12
## 7 -11.70 166.10 82 4.8 43
## 8 -28.11 181.93 194 4.4 15
## 9 -28.74 181.74 211 4.7 35
## 10 -17.47 179.59 622 4.3 19
## 11 -21.44 180.69 583 4.4 13
## 12 -12.26 167.00 249 4.6 16
## 13 -18.54 182.11 554 4.4 19
## 14 -21.00 181.66 600 4.4 10
## 15 -20.70 169.92 139 6.1 94
## 16 -15.94 184.95 306 4.3 11
## 17 -13.64 165.96 50 6.0 83
## 18 -17.83 181.50 590 4.5 21
## 19 -23.50 179.78 570 4.4 13
## 20 -22.63 180.31 598 4.4 18
## 21 -20.84 181.16 576 4.5 17
## 22 -10.98 166.32 211 4.2 12
## 23 -23.30 180.16 512 4.4 18
## 24 -30.20 182.00 125 4.7 22
## 25 -19.66 180.28 431 5.4 57
## 26 -17.94 181.49 537 4.0 15
## 27 -14.72 167.51 155 4.6 18
## 28 -16.46 180.79 498 5.2 79
## 29 -20.97 181.47 582 4.5 25
## 30 -19.84 182.37 328 4.4 17
## 31 -22.58 179.24 553 4.6 21
## 32 -16.32 166.74 50 4.7 30
## 33 -15.55 185.05 292 4.8 42
## 34 -23.55 180.80 349 4.0 10
## 35 -16.30 186.00 48 4.5 10
## 36 -25.82 179.33 600 4.3 13
## 37 -18.73 169.23 206 4.5 17
## 38 -17.64 181.28 574 4.6 17
## 39 -17.66 181.40 585 4.1 17
## 40 -18.82 169.33 230 4.4 11
## 41 -37.37 176.78 263 4.7 34
## 42 -15.31 186.10 96 4.6 32
## 43 -24.97 179.82 511 4.4 23
## 44 -15.49 186.04 94 4.3 26
## 45 -19.23 169.41 246 4.6 27
## 46 -30.10 182.30 56 4.9 34
## 47 -26.40 181.70 329 4.5 24
## 48 -11.77 166.32 70 4.4 18
## 49 -24.12 180.08 493 4.3 21
## 50 -18.97 185.25 129 5.1 73
## 51 -18.75 182.35 554 4.2 13
## 52 -19.26 184.42 223 4.0 15
## 53 -22.75 173.20 46 4.6 26
## 54 -21.37 180.67 593 4.3 13
## 55 -20.10 182.16 489 4.2 16
## 56 -19.85 182.13 562 4.4 31
## 57 -22.70 181.00 445 4.5 17
## 58 -22.06 180.60 584 4.0 11
## 59 -17.80 181.35 535 4.4 23
## 60 -24.20 179.20 530 4.3 12
## 61 -20.69 181.55 582 4.7 35
## 62 -21.16 182.40 260 4.1 12
## 63 -13.82 172.38 613 5.0 61
## 64 -11.49 166.22 84 4.6 32
## 65 -20.68 181.41 593 4.9 40
## 66 -17.10 184.93 286 4.7 25
## 67 -20.14 181.60 587 4.1 13
## 68 -21.96 179.62 627 5.0 45
## 69 -20.42 181.86 530 4.5 27
## 70 -15.46 187.81 40 5.5 91
## 71 -15.31 185.80 152 4.0 11
## 72 -19.86 184.35 201 4.5 30
## 73 -11.55 166.20 96 4.3 14
## 74 -23.74 179.99 506 5.2 75
## 75 -17.70 181.23 546 4.4 35
## 76 -23.54 180.04 564 4.3 15
## 77 -19.21 184.70 197 4.1 11
## 78 -12.11 167.06 265 4.5 23
## 79 -21.81 181.71 323 4.2 15
## 80 -28.98 181.11 304 5.3 60
## 81 -34.02 180.21 75 5.2 65
## 82 -23.84 180.99 367 4.5 27
## 83 -19.57 182.38 579 4.6 38
## 84 -20.12 183.40 284 4.3 15
## 85 -17.70 181.70 450 4.0 11
## 86 -19.66 184.31 170 4.3 15
## 87 -21.50 170.50 117 4.7 32
## 88 -23.64 179.96 538 4.5 26
## 89 -15.43 186.30 123 4.2 16
## 90 -15.41 186.44 69 4.3 42
## 91 -15.48 167.53 128 5.1 61
## 92 -13.36 167.06 236 4.7 22
## 93 -20.64 182.02 497 5.2 64
## 94 -19.72 169.71 271 4.2 14
## 95 -15.44 185.26 224 4.2 21
## 96 -19.73 182.40 375 4.0 18
## 97 -27.24 181.11 365 4.5 21
## 98 -18.16 183.41 306 5.2 54
## 99 -13.66 166.54 50 5.1 45
## 100 -24.57 179.92 484 4.7 33
## 101 -16.98 185.61 108 4.1 12
## 102 -26.20 178.41 583 4.6 25
## 103 -21.88 180.39 608 4.7 30
## 104 -33.00 181.60 72 4.7 22
## 105 -21.33 180.69 636 4.6 29
## 106 -19.44 183.50 293 4.2 15
## 107 -34.89 180.60 42 4.4 25
## 108 -20.24 169.49 100 4.6 22
## 109 -22.55 185.90 42 5.7 76
## 110 -36.95 177.81 146 5.0 35
## 111 -15.75 185.23 280 4.5 28
## 112 -16.85 182.31 388 4.2 14
## 113 -19.06 182.45 477 4.0 16
## 114 -26.11 178.30 617 4.8 39
## 115 -26.20 178.35 606 4.4 21
## 116 -26.13 178.31 609 4.2 25
## 117 -13.66 172.23 46 5.3 67
## 118 -13.47 172.29 64 4.7 14
## 119 -14.60 167.40 178 4.8 52
## 120 -18.96 169.48 248 4.2 13
## 121 -14.65 166.97 82 4.8 28
## 122 -19.90 178.90 81 4.3 11
## 123 -22.05 180.40 606 4.7 27
## 124 -19.22 182.43 571 4.5 23
## 125 -31.24 180.60 328 4.4 18
## 126 -17.93 167.89 49 5.1 43
## 127 -19.30 183.84 517 4.2 21
## 128 -26.53 178.57 600 5.0 69
## 129 -27.72 181.70 94 4.8 59
## 130 -19.19 183.51 307 4.3 19
## 131 -17.43 185.43 189 4.5 22
## 132 -17.05 181.22 527 4.2 24
## 133 -19.52 168.98 63 4.5 21
## 134 -23.71 180.30 510 4.6 30
## 135 -21.30 180.82 624 4.3 14
## 136 -16.24 168.02 53 4.7 12
## 137 -16.14 187.32 42 5.1 68
## 138 -23.95 182.80 199 4.6 14
## 139 -25.20 182.60 149 4.9 31
## 140 -18.84 184.16 210 4.2 17
## 141 -12.66 169.46 658 4.6 43
## 142 -20.65 181.40 582 4.0 14
## 143 -13.23 167.10 220 5.0 46
## 144 -29.91 181.43 205 4.4 34
## 145 -14.31 173.50 614 4.2 23
## 146 -20.10 184.40 186 4.2 10
## 147 -17.80 185.17 97 4.4 22
## 148 -21.27 173.49 48 4.9 42
## 149 -23.58 180.17 462 5.3 63
## 150 -17.90 181.50 573 4.0 19
## 151 -23.34 184.50 56 5.7 106
## 152 -15.56 167.62 127 6.4 122
## 153 -23.83 182.56 229 4.3 24
## 154 -11.80 165.80 112 4.2 20
## 155 -15.54 167.68 140 4.7 16
## 156 -20.65 181.32 597 4.7 39
## 157 -11.75 166.07 69 4.2 14
## 158 -24.81 180.00 452 4.3 19
## 159 -20.90 169.84 93 4.9 31
## 160 -11.34 166.24 103 4.6 30
## 161 -17.98 180.50 626 4.1 19
## 162 -24.34 179.52 504 4.8 34
## 163 -13.86 167.16 202 4.6 30
## 164 -35.56 180.20 42 4.6 32
## 165 -35.48 179.90 59 4.8 35
## 166 -34.20 179.43 40 5.0 37
## 167 -26.00 182.12 205 5.6 98
## 168 -19.89 183.84 244 5.3 73
## 169 -23.43 180.00 553 4.7 41
## 170 -18.89 169.42 239 4.5 27
## 171 -17.82 181.83 640 4.3 24
## 172 -25.68 180.34 434 4.6 41
## 173 -20.20 180.90 627 4.1 11
## 174 -15.20 184.68 99 4.1 14
## 175 -15.03 182.29 399 4.1 10
## 176 -32.22 180.20 216 5.7 90
## 177 -22.64 180.64 544 5.0 50
## 178 -17.42 185.16 206 4.5 22
## 179 -17.84 181.48 542 4.1 20
## 180 -15.02 184.24 339 4.6 27
## 181 -18.04 181.75 640 4.5 47
## 182 -24.60 183.50 67 4.3 25
## 183 -19.88 184.30 161 4.4 17
## 184 -20.30 183.00 375 4.2 15
## 185 -20.45 181.85 534 4.1 14
## 186 -17.67 187.09 45 4.9 62
## 187 -22.30 181.90 309 4.3 11
## 188 -19.85 181.85 576 4.9 54
## 189 -24.27 179.88 523 4.6 24
## 190 -15.85 185.13 290 4.6 29
## 191 -20.02 184.09 234 5.3 71
## 192 -18.56 169.31 223 4.7 35
## 193 -17.87 182.00 569 4.6 12
## 194 -24.08 179.50 605 4.1 21
## 195 -32.20 179.61 422 4.6 41
## 196 -20.36 181.19 637 4.2 23
## 197 -23.85 182.53 204 4.6 27
## 198 -24.00 182.75 175 4.5 14
## 199 -20.41 181.74 538 4.3 31
## 200 -17.72 180.30 595 5.2 74
## 201 -19.67 182.18 360 4.3 23
## 202 -17.70 182.20 445 4.0 12
## 203 -16.23 183.59 367 4.7 35
## 204 -26.72 183.35 190 4.5 36
## 205 -12.95 169.09 629 4.5 19
## 206 -21.97 182.32 261 4.3 13
## 207 -21.96 180.54 603 5.2 66
## 208 -20.32 181.69 508 4.5 14
## 209 -30.28 180.62 350 4.7 32
## 210 -20.20 182.30 533 4.2 11
## 211 -30.66 180.13 411 4.7 42
## 212 -16.17 184.10 338 4.3 13
## 213 -28.25 181.71 226 4.1 19
## 214 -20.47 185.68 93 5.4 85
## 215 -23.55 180.27 535 4.3 22
## 216 -20.94 181.58 573 4.3 21
## 217 -26.67 182.40 186 4.2 17
## 218 -18.13 181.52 618 4.6 41
## 219 -20.21 183.83 242 4.4 29
## 220 -18.31 182.39 342 4.2 14
## 221 -16.52 185.70 90 4.7 30
## 222 -22.36 171.65 130 4.6 39
## 223 -22.43 184.48 65 4.9 48
## 224 -20.37 182.10 397 4.2 22
## 225 -23.77 180.16 505 4.5 26
## 226 -13.65 166.66 71 4.9 52
## 227 -21.55 182.90 207 4.2 18
## 228 -16.24 185.75 154 4.5 22
## 229 -23.73 182.53 232 5.0 55
## 230 -22.34 171.52 106 5.0 43
## 231 -19.40 180.94 664 4.7 34
## 232 -24.64 180.81 397 4.3 24
## 233 -16.00 182.82 431 4.4 16
## 234 -19.62 185.35 57 4.9 31
## 235 -23.84 180.13 525 4.5 15
## 236 -23.54 179.93 574 4.0 12
## 237 -28.23 182.68 74 4.4 20
## 238 -21.68 180.63 617 5.0 63
## 239 -13.44 166.53 44 4.7 27
## 240 -24.96 180.22 470 4.8 41
## 241 -20.08 182.74 298 4.5 33
## 242 -24.36 182.84 148 4.1 16
## 243 -14.70 166.00 48 5.3 16
## 244 -18.20 183.68 107 4.8 52
## 245 -16.65 185.51 218 5.0 52
## 246 -18.11 181.67 597 4.6 28
## 247 -17.95 181.65 619 4.3 26
## 248 -15.50 186.90 46 4.7 18
## 249 -23.36 180.01 553 5.3 61
## 250 -19.15 169.50 150 4.2 12
## 251 -10.97 166.26 180 4.7 26
## 252 -14.85 167.24 97 4.5 26
## 253 -17.80 181.38 587 5.1 47
## 254 -22.50 170.40 106 4.9 38
## 255 -29.10 182.10 179 4.4 19
## 256 -20.32 180.88 680 4.2 22
## 257 -16.09 184.89 304 4.6 34
## 258 -19.18 169.33 254 4.7 35
## 259 -23.81 179.36 521 4.2 23
## 260 -23.79 179.89 526 4.9 43
## 261 -19.02 184.23 270 5.1 72
## 262 -20.90 181.51 548 4.7 32
## 263 -19.06 169.01 158 4.4 10
## 264 -17.88 181.47 562 4.4 27
## 265 -19.41 183.05 300 4.2 16
## 266 -26.17 184.20 65 4.9 37
## 267 -14.95 167.24 130 4.6 16
## 268 -18.73 168.80 82 4.4 14
## 269 -20.21 182.37 482 4.6 37
## 270 -21.29 180.85 607 4.5 23
## 271 -19.76 181.41 105 4.4 15
## 272 -22.09 180.38 590 4.9 35
## 273 -23.80 179.90 498 4.1 12
## 274 -20.16 181.99 504 4.2 11
## 275 -22.13 180.38 577 5.7 104
## 276 -17.44 181.40 529 4.6 25
## 277 -23.33 180.18 528 5.0 59
## 278 -24.78 179.22 492 4.3 16
## 279 -22.00 180.52 561 4.5 19
## 280 -19.13 182.51 579 5.2 56
## 281 -30.72 180.10 413 4.4 22
## 282 -22.32 180.54 565 4.2 12
## 283 -16.45 177.77 138 4.6 17
## 284 -17.70 185.00 383 4.0 10
## 285 -17.95 184.68 260 4.4 21
## 286 -24.40 179.85 522 4.7 29
## 287 -19.30 180.60 671 4.2 16
## 288 -21.13 185.32 123 4.7 36
## 289 -18.07 181.57 572 4.5 26
## 290 -20.60 182.28 529 5.0 50
## 291 -18.48 181.49 641 5.0 49
## 292 -13.34 166.20 67 4.8 18
## 293 -20.92 181.50 546 4.6 31
## 294 -25.31 179.69 507 4.6 35
## 295 -15.24 186.21 158 5.0 57
## 296 -16.40 185.86 148 5.0 47
## 297 -24.57 178.40 562 5.6 80
## 298 -17.94 181.51 601 4.0 16
## 299 -30.64 181.20 175 4.0 16
## 300 -18.64 169.32 260 4.6 23
## 301 -13.09 169.28 654 4.4 22
## 302 -19.68 184.14 242 4.8 40
## 303 -16.44 185.74 126 4.7 30
## 304 -21.09 181.38 555 4.6 15
## 305 -14.99 171.39 637 4.3 21
## 306 -23.30 179.70 500 4.7 29
## 307 -17.68 181.36 515 4.1 19
## 308 -22.00 180.53 583 4.9 20
## 309 -21.38 181.39 501 4.6 36
## 310 -32.62 181.50 55 4.8 26
## 311 -13.05 169.58 644 4.9 68
## 312 -12.93 169.63 641 5.1 57
## 313 -18.60 181.91 442 5.4 82
## 314 -21.34 181.41 464 4.5 21
## 315 -21.48 183.78 200 4.9 54
## 316 -17.40 181.02 479 4.4 14
## 317 -17.32 181.03 497 4.1 13
## 318 -18.77 169.24 218 5.3 53
## 319 -26.16 179.50 492 4.5 25
## 320 -12.59 167.10 325 4.9 26
## 321 -14.82 167.32 123 4.8 28
## 322 -21.79 183.48 210 5.2 69
## 323 -19.83 182.04 575 4.4 23
## 324 -29.50 182.31 129 4.4 14
## 325 -12.49 166.36 74 4.9 55
## 326 -26.10 182.30 49 4.4 11
## 327 -21.04 181.20 483 4.2 10
## 328 -10.78 165.77 93 4.6 20
## 329 -20.76 185.77 118 4.6 15
## 330 -11.41 166.24 83 5.3 55
## 331 -19.10 183.87 61 5.3 42
## 332 -23.91 180.00 534 4.5 11
## 333 -27.33 182.60 42 4.4 11
## 334 -12.25 166.60 219 5.0 28
## 335 -23.49 179.07 544 5.1 58
## 336 -27.18 182.18 56 4.5 14
## 337 -25.80 182.10 68 4.5 26
## 338 -27.19 182.18 69 5.4 68
## 339 -27.27 182.38 45 4.5 16
## 340 -27.10 182.18 43 4.7 17
## 341 -27.22 182.28 65 4.2 14
## 342 -27.38 181.70 80 4.8 13
## 343 -27.27 182.50 51 4.5 13
## 344 -27.54 182.50 68 4.3 12
## 345 -27.20 182.39 69 4.3 14
## 346 -27.71 182.47 103 4.3 11
## 347 -27.60 182.40 61 4.6 11
## 348 -27.38 182.39 69 4.5 12
## 349 -21.54 185.48 51 5.0 29
## 350 -27.21 182.43 55 4.6 10
## 351 -28.96 182.61 54 4.6 15
## 352 -12.01 166.29 59 4.9 27
## 353 -17.46 181.32 573 4.1 17
## 354 -30.17 182.02 56 5.5 68
## 355 -27.27 182.36 65 4.7 21
## 356 -17.79 181.32 587 5.0 49
## 357 -22.19 171.40 150 5.1 49
## 358 -17.10 182.68 403 5.5 82
## 359 -27.18 182.53 60 4.6 21
## 360 -11.64 166.47 130 4.7 19
## 361 -17.98 181.58 590 4.2 14
## 362 -16.90 185.72 135 4.0 22
## 363 -21.98 179.60 583 5.4 67
## 364 -32.14 179.90 406 4.3 19
## 365 -18.80 169.21 221 4.4 16
## 366 -26.78 183.61 40 4.6 22
## 367 -20.43 182.37 502 5.1 48
## 368 -18.30 183.20 103 4.5 14
## 369 -15.83 182.51 423 4.2 21
## 370 -23.44 182.93 158 4.1 20
## 371 -23.73 179.99 527 5.1 49
## 372 -19.89 184.08 219 5.4 105
## 373 -17.59 181.09 536 5.1 61
## 374 -19.77 181.40 630 5.1 54
## 375 -20.31 184.06 249 4.4 21
## 376 -15.33 186.75 48 5.7 123
## 377 -18.20 181.60 553 4.4 14
## 378 -15.36 186.66 112 5.1 57
## 379 -15.29 186.42 153 4.6 31
## 380 -15.36 186.71 130 5.5 95
## 381 -16.24 167.95 188 5.1 68
## 382 -13.47 167.14 226 4.4 26
## 383 -25.50 182.82 124 5.0 25
## 384 -14.32 167.33 204 5.0 49
## 385 -20.04 182.01 605 5.1 49
## 386 -28.83 181.66 221 5.1 63
## 387 -17.82 181.49 573 4.2 14
## 388 -27.23 180.98 401 4.5 39
## 389 -10.72 165.99 195 4.0 14
## 390 -27.00 183.88 56 4.9 36
## 391 -20.36 186.16 102 4.3 21
## 392 -27.17 183.68 44 4.8 27
## 393 -20.94 181.26 556 4.4 21
## 394 -17.46 181.90 417 4.2 14
## 395 -21.04 181.20 591 4.9 45
## 396 -23.70 179.60 646 4.2 21
## 397 -17.72 181.42 565 5.3 89
## 398 -15.87 188.13 52 5.0 30
## 399 -17.84 181.30 535 5.7 112
## 400 -13.45 170.30 641 5.3 93
## 401 -30.80 182.16 41 4.7 24
## 402 -11.63 166.14 109 4.6 36
## 403 -30.40 181.40 40 4.3 17
## 404 -26.18 178.59 548 5.4 65
## 405 -15.70 184.50 118 4.4 30
## 406 -17.95 181.50 593 4.3 16
## 407 -20.51 182.30 492 4.3 23
## 408 -15.36 167.51 123 4.7 28
## 409 -23.61 180.23 475 4.4 26
## 410 -33.20 181.60 153 4.2 21
## 411 -17.68 186.80 112 4.5 35
## 412 -22.24 184.56 99 4.8 57
## 413 -20.07 169.14 66 4.8 37
## 414 -25.04 180.10 481 4.3 15
## 415 -21.50 185.20 139 4.4 15
## 416 -14.28 167.26 211 5.1 51
## 417 -14.43 167.26 151 4.4 17
## 418 -32.70 181.70 211 4.4 40
## 419 -34.10 181.80 246 4.3 23
## 420 -19.70 186.20 47 4.8 19
## 421 -24.19 180.38 484 4.3 27
## 422 -26.60 182.77 119 4.5 29
## 423 -17.04 186.80 70 4.1 22
## 424 -22.10 179.71 579 5.1 58
## 425 -32.60 180.90 57 4.7 44
## 426 -33.00 182.40 176 4.6 28
## 427 -20.58 181.24 602 4.7 44
## 428 -20.61 182.60 488 4.6 12
## 429 -19.47 169.15 149 4.4 15
## 430 -17.47 180.96 546 4.2 23
## 431 -18.40 183.40 343 4.1 10
## 432 -23.33 180.26 530 4.7 22
## 433 -18.55 182.23 563 4.0 17
## 434 -26.16 178.47 537 4.8 33
## 435 -21.80 183.20 325 4.4 19
## 436 -27.63 182.93 80 4.3 14
## 437 -18.89 169.48 259 4.4 21
## 438 -20.30 182.30 476 4.5 10
## 439 -20.56 182.04 499 4.5 29
## 440 -16.10 185.32 257 4.7 30
## 441 -12.66 166.37 165 4.3 18
## 442 -21.05 184.68 136 4.7 29
## 443 -17.97 168.52 146 4.8 33
## 444 -19.83 182.54 524 4.6 14
## 445 -22.55 183.81 82 5.1 68
## 446 -22.28 183.52 90 4.7 19
## 447 -15.72 185.64 138 4.3 21
## 448 -20.85 181.59 499 5.1 91
## 449 -21.11 181.50 538 5.5 104
## 450 -25.31 180.15 467 4.5 25
## 451 -26.46 182.50 184 4.3 11
## 452 -24.09 179.68 538 4.3 21
## 453 -16.96 167.70 45 4.7 23
## 454 -23.19 182.80 237 4.3 18
## 455 -20.81 184.70 162 4.3 20
## 456 -15.03 167.32 136 4.6 20
## 457 -18.06 181.59 604 4.5 23
## 458 -19.00 185.60 107 4.5 15
## 459 -23.53 179.99 538 5.4 87
## 460 -18.18 180.63 639 4.6 39
## 461 -15.66 186.80 45 4.4 11
## 462 -18.00 180.62 636 5.0 100
## 463 -18.08 180.70 628 5.2 72
## 464 -18.05 180.86 632 4.4 15
## 465 -29.90 181.16 215 5.1 51
## 466 -20.90 181.90 556 4.4 17
## 467 -15.61 167.50 135 4.4 21
## 468 -16.03 185.43 297 4.8 25
## 469 -17.68 181.11 568 4.4 22
## 470 -31.94 180.57 168 4.7 39
## 471 -19.14 184.36 269 4.7 31
## 472 -18.00 185.48 143 4.4 29
## 473 -16.95 185.94 95 4.3 12
## 474 -10.79 166.06 142 5.0 40
## 475 -20.83 185.90 104 4.5 19
## 476 -32.90 181.60 169 4.6 27
## 477 -37.93 177.47 65 5.4 65
## 478 -29.09 183.20 54 4.6 23
## 479 -23.56 180.23 474 4.5 13
## 480 -19.60 185.20 125 4.4 13
## 481 -21.39 180.68 617 4.5 18
## 482 -14.85 184.87 294 4.1 10
## 483 -22.70 183.30 180 4.0 13
## 484 -32.42 181.21 47 4.9 39
## 485 -17.90 181.30 593 4.1 13
## 486 -23.58 183.40 94 5.2 79
## 487 -34.40 180.50 201 4.4 41
## 488 -17.61 181.20 537 4.1 11
## 489 -21.07 181.13 594 4.9 43
## 490 -13.84 170.62 638 4.6 20
## 491 -30.24 181.63 80 4.5 17
## 492 -18.49 169.04 211 4.8 30
## 493 -23.45 180.23 520 4.2 19
## 494 -16.04 183.54 384 4.2 23
## 495 -17.14 185.31 223 4.1 15
## 496 -22.54 172.91 54 5.5 71
## 497 -15.90 185.30 57 4.4 19
## 498 -30.04 181.20 49 4.8 20
## 499 -24.03 180.22 508 4.2 23
## 500 -18.89 184.46 242 4.8 36
## 501 -16.51 187.10 62 4.9 46
## 502 -20.10 186.30 63 4.6 19
## 503 -21.06 183.81 203 4.5 34
## 504 -13.07 166.87 132 4.4 24
## 505 -23.46 180.09 543 4.6 28
## 506 -19.41 182.30 589 4.2 19
## 507 -11.81 165.98 51 4.7 28
## 508 -11.76 165.96 45 4.4 51
## 509 -12.08 165.76 63 4.5 51
## 510 -25.59 180.02 485 4.9 48
## 511 -26.54 183.63 66 4.7 34
## 512 -20.90 184.28 58 5.5 92
## 513 -16.99 187.00 70 4.7 30
## 514 -23.46 180.17 541 4.6 32
## 515 -17.81 181.82 598 4.1 14
## 516 -15.17 187.20 50 4.7 28
## 517 -11.67 166.02 102 4.6 21
## 518 -20.75 184.52 144 4.3 25
## 519 -19.50 186.90 58 4.4 20
## 520 -26.18 179.79 460 4.7 44
## 521 -20.66 185.77 69 4.3 25
## 522 -19.22 182.54 570 4.1 22
## 523 -24.68 183.33 70 4.7 30
## 524 -15.43 167.38 137 4.5 16
## 525 -32.45 181.15 41 5.5 81
## 526 -21.31 180.84 586 4.5 17
## 527 -15.44 167.18 140 4.6 44
## 528 -13.26 167.01 213 5.1 70
## 529 -15.26 183.13 393 4.4 28
## 530 -33.57 180.80 51 4.7 35
## 531 -15.77 167.01 64 5.5 73
## 532 -15.79 166.83 45 4.6 39
## 533 -21.00 183.20 296 4.0 16
## 534 -16.28 166.94 50 4.6 24
## 535 -23.28 184.60 44 4.8 34
## 536 -16.10 167.25 68 4.7 36
## 537 -17.70 181.31 549 4.7 33
## 538 -15.96 166.69 150 4.2 20
## 539 -15.95 167.34 47 5.4 87
## 540 -17.56 181.59 543 4.6 34
## 541 -15.90 167.42 40 5.5 86
## 542 -15.29 166.90 100 4.2 15
## 543 -15.86 166.85 85 4.5 22
## 544 -16.20 166.80 98 4.5 21
## 545 -15.71 166.91 58 4.8 20
## 546 -16.45 167.54 125 4.6 18
## 547 -11.54 166.18 89 5.4 80
## 548 -19.61 181.91 590 4.6 34
## 549 -15.61 187.15 49 5.0 30
## 550 -21.16 181.41 543 4.3 17
## 551 -20.65 182.22 506 4.3 24
## 552 -20.33 168.71 40 4.8 38
## 553 -15.08 166.62 42 4.7 23
## 554 -23.28 184.61 76 4.7 36
## 555 -23.44 184.60 63 4.8 27
## 556 -23.12 184.42 104 4.2 17
## 557 -23.65 184.46 93 4.2 16
## 558 -22.91 183.95 64 5.9 118
## 559 -22.06 180.47 587 4.6 28
## 560 -13.56 166.49 83 4.5 25
## 561 -17.99 181.57 579 4.9 49
## 562 -23.92 184.47 40 4.7 17
## 563 -30.69 182.10 62 4.9 25
## 564 -21.92 182.80 273 5.3 78
## 565 -25.04 180.97 393 4.2 21
## 566 -19.92 183.91 264 4.2 23
## 567 -27.75 182.26 174 4.5 18
## 568 -17.71 181.18 574 5.2 67
## 569 -19.60 183.84 309 4.5 23
## 570 -34.68 179.82 75 5.6 79
## 571 -14.46 167.26 195 5.2 87
## 572 -18.85 187.55 44 4.8 35
## 573 -17.02 182.41 420 4.5 29
## 574 -20.41 186.51 63 5.0 28
## 575 -18.18 182.04 609 4.4 26
## 576 -16.49 187.80 40 4.5 18
## 577 -17.74 181.31 575 4.6 42
## 578 -20.49 181.69 559 4.5 24
## 579 -18.51 182.64 405 5.2 74
## 580 -27.28 183.40 70 5.1 54
## 581 -15.90 167.16 41 4.8 42
## 582 -20.57 181.33 605 4.3 18
## 583 -11.25 166.36 130 5.1 55
## 584 -20.04 181.87 577 4.7 19
## 585 -20.89 181.25 599 4.6 20
## 586 -16.62 186.74 82 4.8 51
## 587 -20.09 168.75 50 4.6 23
## 588 -24.96 179.87 480 4.4 25
## 589 -20.95 181.42 559 4.6 27
## 590 -23.31 179.27 566 5.1 49
## 591 -20.95 181.06 611 4.3 20
## 592 -21.58 181.90 409 4.4 19
## 593 -13.62 167.15 209 4.7 30
## 594 -12.72 166.28 70 4.8 47
## 595 -21.79 185.00 74 4.1 15
## 596 -20.48 169.76 134 4.6 33
## 597 -12.84 166.78 150 4.9 35
## 598 -17.02 182.93 406 4.0 17
## 599 -23.89 182.39 243 4.7 32
## 600 -23.07 184.03 89 4.7 32
## 601 -27.98 181.96 53 5.2 89
## 602 -28.10 182.25 68 4.6 18
## 603 -21.24 180.81 605 4.6 34
## 604 -21.24 180.86 615 4.9 23
## 605 -19.89 174.46 546 5.7 99
## 606 -32.82 179.80 176 4.7 26
## 607 -22.00 185.50 52 4.4 18
## 608 -21.57 185.62 66 4.9 38
## 609 -24.50 180.92 377 4.8 43
## 610 -33.03 180.20 186 4.6 27
## 611 -30.09 182.40 51 4.4 18
## 612 -22.75 170.99 67 4.8 35
## 613 -17.99 168.98 234 4.7 28
## 614 -19.60 181.87 597 4.2 18
## 615 -15.65 186.26 64 5.1 54
## 616 -17.78 181.53 511 4.8 56
## 617 -22.04 184.91 47 4.9 47
## 618 -20.06 168.69 49 5.1 49
## 619 -18.07 181.54 546 4.3 28
## 620 -12.85 165.67 75 4.4 30
## 621 -33.29 181.30 60 4.7 33
## 622 -34.63 179.10 278 4.7 24
## 623 -24.18 179.02 550 5.3 86
## 624 -23.78 180.31 518 5.1 71
## 625 -22.37 171.50 116 4.9 38
## 626 -23.97 179.91 518 4.5 23
## 627 -34.12 181.75 75 4.7 41
## 628 -25.25 179.86 491 4.2 23
## 629 -22.87 172.65 56 5.1 50
## 630 -18.48 182.37 376 4.8 57
## 631 -21.46 181.02 584 4.2 18
## 632 -28.56 183.47 48 4.8 56
## 633 -28.56 183.59 53 4.4 20
## 634 -21.30 180.92 617 4.5 26
## 635 -20.08 183.22 294 4.3 18
## 636 -18.82 182.21 417 5.6 129
## 637 -19.51 183.97 280 4.0 16
## 638 -12.05 167.39 332 5.0 36
## 639 -17.40 186.54 85 4.2 28
## 640 -23.93 180.18 525 4.6 31
## 641 -21.23 181.09 613 4.6 18
## 642 -16.23 167.91 182 4.5 28
## 643 -28.15 183.40 57 5.0 32
## 644 -20.81 185.01 79 4.7 42
## 645 -20.72 181.41 595 4.6 36
## 646 -23.29 184.00 164 4.8 50
## 647 -38.46 176.03 148 4.6 44
## 648 -15.48 186.73 82 4.4 17
## 649 -37.03 177.52 153 5.6 87
## 650 -20.48 181.38 556 4.2 13
## 651 -18.12 181.88 649 5.4 88
## 652 -18.17 181.98 651 4.8 43
## 653 -11.40 166.07 93 5.6 94
## 654 -23.10 180.12 533 4.4 27
## 655 -14.28 170.34 642 4.7 29
## 656 -22.87 171.72 47 4.6 27
## 657 -17.59 180.98 548 5.1 79
## 658 -27.60 182.10 154 4.6 22
## 659 -17.94 180.60 627 4.5 29
## 660 -17.88 180.58 622 4.2 23
## 661 -30.01 180.80 286 4.8 43
## 662 -19.19 182.30 390 4.9 48
## 663 -18.14 180.87 624 5.5 105
## 664 -23.46 180.11 539 5.0 41
## 665 -18.44 181.04 624 4.2 21
## 666 -18.21 180.87 631 5.2 69
## 667 -18.26 180.98 631 4.8 36
## 668 -15.85 184.83 299 4.4 30
## 669 -23.82 180.09 498 4.8 40
## 670 -18.60 184.28 255 4.4 31
## 671 -17.80 181.32 539 4.1 12
## 672 -10.78 166.10 195 4.9 45
## 673 -18.12 181.71 594 4.6 24
## 674 -19.34 182.62 573 4.5 32
## 675 -15.34 167.10 128 5.3 18
## 676 -24.97 182.85 137 4.8 40
## 677 -15.97 186.08 143 4.6 41
## 678 -23.47 180.24 511 4.8 37
## 679 -23.11 179.15 564 4.7 17
## 680 -20.54 181.66 559 4.9 50
## 681 -18.92 169.37 248 5.3 60
## 682 -20.16 184.27 210 4.4 27
## 683 -25.48 180.94 390 4.6 33
## 684 -18.19 181.74 616 4.3 17
## 685 -15.35 186.40 98 4.4 17
## 686 -18.69 169.10 218 4.2 27
## 687 -18.89 181.24 655 4.1 14
## 688 -17.61 183.32 356 4.2 15
## 689 -20.93 181.54 564 5.0 64
## 690 -17.60 181.50 548 4.1 10
## 691 -17.96 181.40 655 4.3 20
## 692 -18.80 182.41 385 5.2 67
## 693 -20.61 182.44 518 4.2 10
## 694 -20.74 181.53 598 4.5 36
## 695 -25.23 179.86 476 4.4 29
## 696 -23.90 179.90 579 4.4 16
## 697 -18.07 181.58 603 5.0 65
## 698 -15.43 185.19 249 4.0 11
## 699 -14.30 167.32 208 4.8 25
## 700 -18.04 181.57 587 5.0 51
## 701 -13.90 167.18 221 4.2 21
## 702 -17.64 177.01 545 5.2 91
## 703 -17.98 181.51 586 5.2 68
## 704 -25.00 180.00 488 4.5 10
## 705 -19.45 184.48 246 4.3 15
## 706 -16.11 187.48 61 4.5 19
## 707 -23.73 179.98 524 4.6 11
## 708 -17.74 186.78 104 5.1 71
## 709 -21.56 183.23 271 4.4 36
## 710 -20.97 181.72 487 4.3 16
## 711 -15.45 186.73 83 4.7 37
## 712 -15.93 167.91 183 5.6 109
## 713 -21.47 185.86 55 4.9 46
## 714 -21.44 170.45 166 5.1 22
## 715 -22.16 180.49 586 4.6 13
## 716 -13.36 172.76 618 4.4 18
## 717 -21.22 181.51 524 4.8 49
## 718 -26.10 182.50 133 4.2 17
## 719 -18.35 185.27 201 4.7 57
## 720 -17.20 182.90 383 4.1 11
## 721 -22.42 171.40 86 4.7 33
## 722 -17.91 181.48 555 4.0 17
## 723 -26.53 178.30 605 4.9 43
## 724 -26.50 178.29 609 5.0 50
## 725 -16.31 168.08 204 4.5 16
## 726 -18.76 169.71 287 4.4 23
## 727 -17.10 182.80 390 4.0 14
## 728 -19.28 182.78 348 4.5 30
## 729 -23.50 180.00 550 4.7 23
## 730 -21.26 181.69 487 4.4 20
## 731 -17.97 181.48 578 4.7 43
## 732 -26.02 181.20 361 4.7 32
## 733 -30.30 180.80 275 4.0 14
## 734 -24.89 179.67 498 4.2 14
## 735 -14.57 167.24 162 4.5 18
## 736 -15.40 186.87 78 4.7 44
## 737 -22.06 183.95 134 4.5 17
## 738 -25.14 178.42 554 4.1 15
## 739 -20.30 181.40 608 4.6 13
## 740 -25.28 181.17 367 4.3 25
## 741 -20.63 181.61 599 4.6 30
## 742 -19.02 186.83 45 5.2 65
## 743 -22.10 185.30 50 4.6 22
## 744 -38.59 175.70 162 4.7 36
## 745 -19.30 183.00 302 5.0 65
## 746 -31.03 181.59 57 5.2 49
## 747 -30.51 181.30 203 4.4 20
## 748 -22.55 183.34 66 4.6 18
## 749 -22.14 180.64 591 4.5 18
## 750 -25.60 180.30 440 4.0 12
## 751 -18.04 181.84 611 4.2 20
## 752 -21.29 185.77 57 5.3 69
## 753 -21.08 180.85 627 5.9 119
## 754 -20.64 169.66 89 4.9 42
## 755 -24.41 180.03 500 4.5 34
## 756 -12.16 167.03 264 4.4 14
## 757 -17.10 185.90 127 5.4 75
## 758 -21.13 185.60 85 5.3 86
## 759 -12.34 167.43 50 5.1 47
## 760 -16.43 186.73 75 4.1 20
## 761 -20.70 184.30 182 4.3 17
## 762 -21.18 180.92 619 4.5 18
## 763 -17.78 185.33 223 4.1 10
## 764 -21.57 183.86 156 5.1 70
## 765 -13.70 166.75 46 5.3 71
## 766 -12.27 167.41 50 4.5 29
## 767 -19.10 184.52 230 4.1 16
## 768 -19.85 184.51 184 4.4 26
## 769 -11.37 166.55 188 4.7 24
## 770 -20.70 186.30 80 4.0 10
## 771 -20.24 185.10 86 5.1 61
## 772 -16.40 182.73 391 4.0 16
## 773 -19.60 184.53 199 4.3 21
## 774 -21.63 180.77 592 4.3 21
## 775 -21.60 180.50 595 4.0 22
## 776 -21.77 181.00 618 4.1 10
## 777 -21.80 183.60 213 4.4 17
## 778 -21.05 180.90 616 4.3 10
## 779 -10.80 165.80 175 4.2 12
## 780 -17.90 181.50 589 4.0 12
## 781 -22.26 171.44 83 4.5 25
## 782 -22.33 171.46 119 4.7 32
## 783 -24.04 184.85 70 5.0 48
## 784 -20.40 186.10 74 4.3 22
## 785 -15.00 184.62 40 5.1 54
## 786 -27.87 183.40 87 4.7 34
## 787 -14.12 166.64 63 5.3 69
## 788 -23.61 180.27 537 5.0 63
## 789 -21.56 185.50 47 4.5 29
## 790 -21.19 181.58 490 5.0 77
## 791 -18.07 181.65 593 4.1 16
## 792 -26.00 178.43 644 4.9 27
## 793 -20.21 181.90 576 4.1 16
## 794 -28.00 182.00 199 4.0 16
## 795 -20.74 180.70 589 4.4 27
## 796 -31.80 180.60 178 4.5 19
## 797 -18.91 169.46 248 4.4 33
## 798 -20.45 182.10 500 4.5 37
## 799 -22.90 183.80 71 4.3 19
## 800 -18.11 181.63 568 4.3 36
## 801 -23.80 184.70 42 5.0 36
## 802 -23.42 180.21 510 4.5 37
## 803 -23.20 184.80 97 4.5 13
## 804 -12.93 169.52 663 4.4 30
## 805 -21.14 181.06 625 4.5 35
## 806 -19.13 184.97 210 4.1 22
## 807 -21.08 181.30 557 4.9 78
## 808 -20.07 181.75 582 4.7 27
## 809 -20.90 182.02 402 4.3 18
## 810 -25.04 179.84 474 4.6 32
## 811 -21.85 180.89 577 4.6 43
## 812 -19.34 186.59 56 5.2 49
## 813 -15.83 167.10 43 4.5 19
## 814 -23.73 183.00 118 4.3 11
## 815 -18.10 181.72 544 4.6 52
## 816 -22.12 180.49 532 4.0 14
## 817 -15.39 185.10 237 4.5 39
## 818 -16.21 186.52 111 4.8 30
## 819 -21.75 180.67 595 4.6 30
## 820 -22.10 180.40 603 4.1 11
## 821 -24.97 179.54 505 4.9 50
## 822 -19.36 186.36 100 4.7 40
## 823 -22.14 179.62 587 4.1 23
## 824 -21.48 182.44 364 4.3 20
## 825 -18.54 168.93 100 4.4 17
## 826 -21.62 182.40 350 4.0 12
## 827 -13.40 166.90 228 4.8 15
## 828 -15.50 185.30 93 4.4 25
## 829 -15.67 185.23 66 4.4 34
## 830 -21.78 183.11 225 4.6 21
## 831 -30.63 180.90 334 4.2 28
## 832 -15.70 185.10 70 4.1 15
## 833 -19.20 184.37 220 4.2 18
## 834 -19.70 182.44 397 4.0 12
## 835 -19.40 182.29 326 4.1 15
## 836 -15.85 185.90 121 4.1 17
## 837 -17.38 168.63 209 4.7 29
## 838 -24.33 179.97 510 4.8 44
## 839 -20.89 185.26 54 5.1 44
## 840 -18.97 169.44 242 5.0 41
## 841 -17.99 181.62 574 4.8 38
## 842 -15.80 185.25 82 4.4 39
## 843 -25.42 182.65 102 5.0 36
## 844 -21.60 169.90 43 5.2 56
## 845 -26.06 180.05 432 4.2 19
## 846 -17.56 181.23 580 4.1 16
## 847 -25.63 180.26 464 4.8 60
## 848 -25.46 179.98 479 4.5 27
## 849 -22.23 180.48 581 5.0 54
## 850 -21.55 181.39 513 5.1 81
## 851 -15.18 185.93 77 4.1 16
## 852 -13.79 166.56 68 4.7 41
## 853 -15.18 167.23 71 5.2 59
## 854 -18.78 186.72 68 4.8 48
## 855 -17.90 181.41 586 4.5 33
## 856 -18.50 185.40 243 4.0 11
## 857 -14.82 171.17 658 4.7 49
## 858 -15.65 185.17 315 4.1 15
## 859 -30.01 181.15 210 4.3 17
## 860 -13.16 167.24 278 4.3 17
## 861 -21.03 180.78 638 4.0 14
## 862 -21.40 180.78 615 4.7 51
## 863 -17.93 181.89 567 4.1 27
## 864 -20.87 181.70 560 4.2 13
## 865 -12.01 166.66 99 4.8 36
## 866 -19.10 169.63 266 4.8 31
## 867 -22.85 181.37 397 4.2 15
## 868 -17.08 185.96 180 4.2 29
## 869 -21.14 174.21 40 5.7 78
## 870 -12.23 167.02 242 6.0 132
## 871 -20.91 181.57 530 4.2 20
## 872 -11.38 167.05 133 4.5 32
## 873 -11.02 167.01 62 4.9 36
## 874 -22.09 180.58 580 4.4 22
## 875 -17.80 181.20 530 4.0 15
## 876 -18.94 182.43 566 4.3 20
## 877 -18.85 182.20 501 4.2 23
## 878 -21.91 181.28 548 4.5 30
## 879 -22.03 179.77 587 4.8 31
## 880 -18.10 181.63 592 4.4 28
## 881 -18.40 184.84 221 4.2 18
## 882 -21.20 181.40 560 4.2 12
## 883 -12.00 166.20 94 5.0 31
## 884 -11.70 166.30 139 4.2 15
## 885 -26.72 182.69 162 5.2 64
## 886 -24.39 178.98 562 4.5 30
## 887 -19.64 169.50 204 4.6 35
## 888 -21.35 170.04 56 5.0 22
## 889 -22.82 184.52 49 5.0 52
## 890 -38.28 177.10 100 5.4 71
## 891 -12.57 167.11 231 4.8 28
## 892 -22.24 180.28 601 4.2 21
## 893 -13.80 166.53 42 5.5 70
## 894 -21.07 183.78 180 4.3 25
## 895 -17.74 181.25 559 4.1 16
## 896 -23.87 180.15 524 4.4 22
## 897 -21.29 185.80 69 4.9 74
## 898 -22.20 180.58 594 4.5 45
## 899 -15.24 185.11 262 4.9 56
## 900 -17.82 181.27 538 4.0 33
## 901 -32.14 180.00 331 4.5 27
## 902 -19.30 185.86 48 5.0 40
## 903 -33.09 180.94 47 4.9 47
## 904 -20.18 181.62 558 4.5 31
## 905 -17.46 181.42 524 4.2 16
## 906 -17.44 181.33 545 4.2 37
## 907 -24.71 179.85 477 4.2 34
## 908 -21.53 170.52 129 5.2 30
## 909 -19.17 169.53 268 4.3 21
## 910 -28.05 182.39 117 5.1 43
## 911 -23.39 179.97 541 4.6 50
## 912 -22.33 171.51 112 4.6 14
## 913 -15.28 185.98 162 4.4 36
## 914 -20.27 181.51 609 4.4 32
## 915 -10.96 165.97 76 4.9 64
## 916 -21.52 169.75 61 5.1 40
## 917 -19.57 184.47 202 4.2 28
## 918 -23.08 183.45 90 4.7 30
## 919 -25.06 182.80 133 4.0 14
## 920 -17.85 181.44 589 5.6 115
## 921 -15.99 167.95 190 5.3 81
## 922 -20.56 184.41 138 5.0 82
## 923 -17.98 181.61 598 4.3 27
## 924 -18.40 181.77 600 4.1 11
## 925 -27.64 182.22 162 5.1 67
## 926 -20.99 181.02 626 4.5 36
## 927 -14.86 167.32 137 4.9 22
## 928 -29.33 182.72 57 5.4 61
## 929 -25.81 182.54 201 4.7 40
## 930 -14.10 166.01 69 4.8 29
## 931 -17.63 185.13 219 4.5 28
## 932 -23.47 180.21 553 4.2 23
## 933 -23.92 180.21 524 4.6 50
## 934 -20.88 185.18 51 4.6 28
## 935 -20.25 184.75 107 5.6 121
## 936 -19.33 186.16 44 5.4 110
## 937 -18.14 181.71 574 4.0 20
## 938 -22.41 183.99 128 5.2 72
## 939 -20.77 181.16 568 4.2 12
## 940 -17.95 181.73 583 4.7 57
## 941 -20.83 181.01 622 4.3 15
## 942 -27.84 182.10 193 4.8 27
## 943 -19.94 182.39 544 4.6 30
## 944 -23.60 183.99 118 5.4 88
## 945 -23.70 184.13 51 4.8 27
## 946 -30.39 182.40 63 4.6 22
## 947 -18.98 182.32 442 4.2 22
## 948 -27.89 182.92 87 5.5 67
## 949 -23.50 184.90 61 4.7 16
## 950 -23.73 184.49 60 4.7 35
## 951 -17.93 181.62 561 4.5 32
## 952 -35.94 178.52 138 5.5 78
## 953 -18.68 184.50 174 4.5 34
## 954 -23.47 179.95 543 4.1 21
## 955 -23.49 180.06 530 4.0 23
## 956 -23.85 180.26 497 4.3 32
## 957 -27.08 183.44 63 4.7 27
## 958 -20.88 184.95 82 4.9 50
## 959 -20.97 181.20 605 4.5 31
## 960 -21.71 183.58 234 4.7 55
## 961 -23.90 184.60 41 4.5 22
## 962 -15.78 167.44 40 4.8 42
## 963 -12.57 166.72 137 4.3 20
## 964 -19.69 184.23 223 4.1 23
## 965 -22.04 183.95 109 5.4 61
## 966 -17.99 181.59 595 4.1 26
## 967 -23.50 180.13 512 4.8 40
## 968 -21.40 180.74 613 4.2 20
## 969 -15.86 166.98 60 4.8 25
## 970 -23.95 184.64 43 5.4 45
## 971 -25.79 182.38 172 4.4 14
## 972 -23.75 184.50 54 5.2 74
## 973 -24.10 184.50 68 4.7 23
## 974 -18.56 169.05 217 4.9 35
## 975 -23.30 184.68 102 4.9 27
## 976 -17.03 185.74 178 4.2 32
## 977 -20.77 183.71 251 4.4 47
## 978 -28.10 183.50 42 4.4 17
## 979 -18.83 182.26 575 4.3 11
## 980 -23.00 170.70 43 4.9 20
## 981 -20.82 181.67 577 5.0 67
## 982 -22.95 170.56 42 4.7 21
## 983 -28.22 183.60 75 4.9 49
## 984 -27.99 183.50 71 4.3 22
## 985 -15.54 187.15 60 4.5 17
## 986 -12.37 166.93 291 4.2 16
## 987 -22.33 171.66 125 5.2 51
## 988 -22.70 170.30 69 4.8 27
## 989 -17.86 181.30 614 4.0 12
## 990 -16.00 184.53 108 4.7 33
## 991 -20.73 181.42 575 4.3 18
## 992 -15.45 181.42 409 4.3 27
## 993 -20.05 183.86 243 4.9 65
## 994 -17.95 181.37 642 4.0 17
## 995 -17.70 188.10 45 4.2 10
## 996 -25.93 179.54 470 4.4 22
## 997 -12.28 167.06 248 4.7 35
## 998 -20.13 184.20 244 4.5 34
## 999 -17.40 187.80 40 4.5 14
## 1000 -21.59 170.56 165 6.0 119
## This also holds for functions
install.packages("dplyr")
## package 'dplyr' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\pdmoerland\AppData\Local\Temp\RtmpURMFjN\downloaded_packages
library(dplyr)
## The function filter occurs in two packages
?filter
x <- 1:100
## Using example code from the function in the stats package throws an error
## because it is hidden by the function in the dplyr package
#filter(x, rep(1, 3))
## You need to indicate which package use with ::
stats::filter(x, rep(1, 3))
## Time Series:
## Start = 1
## End = 100
## Frequency = 1
## [1] NA 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54
## [19] 57 60 63 66 69 72 75 78 81 84 87 90 93 96 99 102 105 108
## [37] 111 114 117 120 123 126 129 132 135 138 141 144 147 150 153 156 159 162
## [55] 165 168 171 174 177 180 183 186 189 192 195 198 201 204 207 210 213 216
## [73] 219 222 225 228 231 234 237 240 243 246 249 252 255 258 261 264 267 270
## [91] 273 276 279 282 285 288 291 294 297 NA
save(titanic3, file="Titanic.RData")
rm(titanic3)
load("Titanic.RData")
getwd()
## [1] "C:/Users/pdmoerland/Dropbox/Education/Computing in R"
#setwd("c:/AMC/Teaching/RCursus") # just an example, note that a forward slash is used
## sort
#install.packages("dplyr")
library(dplyr)
titanic.SortedAge <- arrange(titanic3, age)
head(titanic.SortedAge)
## pclass survived name sex age sibsp
## 764 3rd 1 Dean, Miss. Elizabeth Gladys \\"M female 0.1667 1
## 748 3rd 0 Danbom, Master. Gilbert Sigvard male 0.3333 0
## 1241 3rd 1 Thomas, Master. Assad Alexander male 0.4167 0
## 428 2nd 1 Hamalainen, Master. Viljo male 0.6667 1
## 658 3rd 1 Baclini, Miss. Eugenie female 0.7500 2
## 659 3rd 1 Baclini, Miss. Helene Barbara female 0.7500 2
## parch ticket fare cabin embarked boat body
## 764 2 C.A. 2315 20.5750 Southampton 10 NA
## 748 2 347080 14.4000 Southampton NA
## 1241 1 2625 8.5167 Cherbourg 16 NA
## 428 1 250649 14.5000 Southampton 4 NA
## 658 1 2666 19.2583 Cherbourg C NA
## 659 1 2666 19.2583 Cherbourg C NA
## home.dest dob family agecat
## 764 Devon, England Wichita, KS 1912-02-14 yes (0,18]
## 748 Stanton, IA 1911-12-15 yes (0,18]
## 1241 1911-11-14 yes (0,18]
## 428 Detroit, MI 1911-08-15 yes (0,18]
## 658 Syria New York, NY 1911-07-16 yes (0,18]
## 659 Syria New York, NY 1911-07-16 yes (0,18]
## base R
x <- c(5,8,1)
sort(x)
## [1] 1 5 8
order(x)
## [1] 3 1 2
x[order(x)]
## [1] 1 5 8
z <- data.frame(x=c(5,8,1), y=c("A","M","C"))
z
## x y
## 1 5 A
## 2 8 M
## 3 1 C
z[sort(z$x),]
## x y
## 1 5 A
## NA NA <NA>
## NA.1 NA <NA>
z[order(z$x),]
## x y
## 3 1 C
## 1 5 A
## 2 8 M
## merge
emb <- data.frame(embarked=c("Cherbourg","Queenstown","Southampton"), country=c("France","Ireland","United Kingdom"))
emb
## embarked country
## 1 Cherbourg France
## 2 Queenstown Ireland
## 3 Southampton United Kingdom
titanic3.merged <- left_join(titanic3, emb, by="embarked") # all rows from titanic3, all columns from both
head(titanic3.merged)
## pclass survived name sex age sibsp parch
## 1 1st 1 Allen, Miss. Elisabeth Walton female 29.0000 0 0
## 2 1st 1 Allison, Master. Hudson Trevor male 0.9167 1 2
## 3 1st 0 Allison, Miss. Helen Loraine female 2.0000 1 2
## 4 1st 0 Allison, Mr. Hudson Joshua Crei male 30.0000 1 2
## 5 1st 0 Allison, Mrs. Hudson J C (Bessi female 25.0000 1 2
## 6 1st 1 Anderson, Mr. Harry male 48.0000 0 0
## ticket fare cabin embarked boat body home.dest
## 1 24160 211.3375 B5 Southampton 2 NA St Louis, MO
## 2 113781 151.5500 C22 C26 Southampton 11 NA Montreal, PQ / Chesterville, ON
## 3 113781 151.5500 C22 C26 Southampton NA Montreal, PQ / Chesterville, ON
## 4 113781 151.5500 C22 C26 Southampton 135 Montreal, PQ / Chesterville, ON
## 5 113781 151.5500 C22 C26 Southampton NA Montreal, PQ / Chesterville, ON
## 6 19952 26.5500 E12 Southampton 3 NA New York, NY
## dob family agecat country
## 1 1883-04-14 no (18,30] United Kingdom
## 2 1911-05-16 yes (0,18] United Kingdom
## 3 1910-04-15 yes (0,18] United Kingdom
## 4 1882-04-14 yes (18,30] United Kingdom
## 5 1887-04-14 yes (18,30] United Kingdom
## 6 1864-04-14 no (40,80] United Kingdom
## base R
titanic3.merged <- merge(titanic3, emb)
## wide <-> long
install.packages("tidyr")
## package 'tidyr' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\pdmoerland\AppData\Local\Temp\RtmpURMFjN\downloaded_packages
library(tidyr)
df1 <- data.frame(c("a", "a", "a", "a", "b", "b", "b", "b"), c(1,2,3,4,1,2,3,4), c(0.1, 0.2, 0.3, 0.4, 2.1, 2.2, 2.3, 2.4))
colnames(df1) <- c("Name", "Time", "Value")
df1
## Name Time Value
## 1 a 1 0.1
## 2 a 2 0.2
## 3 a 3 0.3
## 4 a 4 0.4
## 5 b 1 2.1
## 6 b 2 2.2
## 7 b 3 2.3
## 8 b 4 2.4
df1.wide <- pivot_wider(df1, names_from = Time, values_from = Value)
df1.wide
## # A tibble: 2 x 5
## Name `1` `2` `3` `4`
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 a 0.1 0.2 0.3 0.4
## 2 b 2.1 2.2 2.3 2.4
df1.long <- pivot_longer(df1.wide, cols = 2:5, names_to = "Time", values_to = "Value")
df1.long
## # A tibble: 8 x 3
## Name Time Value
## <chr> <chr> <dbl>
## 1 a 1 0.1
## 2 a 2 0.2
## 3 a 3 0.3
## 4 a 4 0.4
## 5 b 1 2.1
## 6 b 2 2.2
## 7 b 3 2.3
## 8 b 4 2.4
arrange(df1.long, Name, Time)
## # A tibble: 8 x 3
## Name Time Value
## <chr> <chr> <dbl>
## 1 a 1 0.1
## 2 a 2 0.2
## 3 a 3 0.3
## 4 a 4 0.4
## 5 b 1 2.1
## 6 b 2 2.2
## 7 b 3 2.3
## 8 b 4 2.4
## base R
df1.wide <- reshape(df1, timevar="Time", idvar="Name", direction="wide", v.names="Value")
df1.wide
## Name Value.1 Value.2 Value.3 Value.4
## 1 a 0.1 0.2 0.3 0.4
## 5 b 2.1 2.2 2.3 2.4
df1.long <- reshape(df1.wide, varying=2:5, direction="long")
df1.long
## Name time Value id
## 1.1 a 1 0.1 1
## 2.1 b 1 2.1 2
## 1.2 a 2 0.2 1
## 2.2 b 2 2.2 2
## 1.3 a 3 0.3 1
## 2.3 b 3 2.3 2
## 1.4 a 4 0.4 1
## 2.4 b 4 2.4 2
df1.long[order(df1.long$Name,df1.long$time),]
## Name time Value id
## 1.1 a 1 0.1 1
## 1.2 a 2 0.2 1
## 1.3 a 3 0.3 1
## 1.4 a 4 0.4 1
## 2.1 b 1 2.1 2
## 2.2 b 2 2.2 2
## 2.3 b 3 2.3 2
## 2.4 b 4 2.4 2
## transformation using within
titanic3 <- within(titanic3, {
agecat <- cut(age, breaks=c(0,18,30,40,80))
family <- factor(ifelse(parch==0 & sibsp==0, "no", "yes"))
})
summary(titanic3[,c("age","agecat","family")])
## age agecat family
## Min. : 0.1667 (0,18] :193 no :790
## 1st Qu.:21.0000 (18,30]:416 yes:519
## Median :28.0000 (30,40]:210
## Mean :29.8811 (40,80]:227
## 3rd Qu.:39.0000 NA's :263
## Max. :80.0000
## NA's :263
## transformation using transform
titanic3 <- transform(titanic3,
agecat = cut(age, breaks=c(0,18,30,40,80)),
family = factor(ifelse(parch==0 & sibsp==0, "no", "yes"))
)
summary(titanic3[,c("age","agecat","family")])
## age agecat family
## Min. : 0.1667 (0,18] :193 no :790
## 1st Qu.:21.0000 (18,30]:416 yes:519
## Median :28.0000 (30,40]:210
## Mean :29.8811 (40,80]:227
## 3rd Qu.:39.0000 NA's :263
## Max. :80.0000
## NA's :263
# crosstable using descr package
install.packages("descr")
## package 'descr' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\pdmoerland\AppData\Local\Temp\RtmpURMFjN\downloaded_packages
library(descr)
descr(titanic3$age)
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 0.1667 21.0000 28.0000 29.8811 39.0000 80.0000 263
with(titanic3, CrossTable(pclass,sex,format="SPSS"))
## Cell Contents
## |-------------------------|
## | Count |
## | Chi-square contribution |
## | Row Percent |
## | Column Percent |
## | Total Percent |
## |-------------------------|
##
## ================================
## sex
## pclass female male Total
## --------------------------------
## 1st 144 179 323
## 7.320 4.047
## 44.6% 55.4% 24.7%
## 30.9% 21.2%
## 11.0% 13.7%
## --------------------------------
## 2nd 106 171 277
## 0.554 0.306
## 38.3% 61.7% 21.2%
## 22.7% 20.3%
## 8.1% 13.1%
## --------------------------------
## 3rd 216 493 709
## 5.250 2.902
## 30.5% 69.5% 54.2%
## 46.4% 58.5%
## 16.5% 37.7%
## --------------------------------
## Total 466 843 1309
## 35.6% 64.4%
## ================================
## summary by subgroup, all produce basically the same output
## basic R functions
aggregate(age~pclass, data=titanic3, FUN=summary)
## pclass age.Min. age.1st Qu. age.Median age.Mean age.3rd Qu. age.Max.
## 1 1st 0.91670 28.00000 39.00000 39.15992 50.00000 80.00000
## 2 2nd 0.66670 22.00000 29.00000 29.50670 36.00000 70.00000
## 3 3rd 0.16670 18.00000 24.00000 24.81637 32.00000 74.00000
by(titanic3,titanic3$pclass,FUN=function(x) summary(x$age))
## titanic3$pclass: 1st
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 0.9167 28.0000 39.0000 39.1599 50.0000 80.0000 39
## ------------------------------------------------------------
## titanic3$pclass: 2nd
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 0.6667 22.0000 29.0000 29.5067 36.0000 70.0000 16
## ------------------------------------------------------------
## titanic3$pclass: 3rd
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 0.1667 18.0000 24.0000 24.8164 32.0000 74.0000 208
with(titanic3, tapply(age,pclass,FUN=summary))
## $`1st`
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 0.9167 28.0000 39.0000 39.1599 50.0000 80.0000 39
##
## $`2nd`
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 0.6667 22.0000 29.0000 29.5067 36.0000 70.0000 16
##
## $`3rd`
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 0.1667 18.0000 24.0000 24.8164 32.0000 74.0000 208
## using doBy package
install.packages("doBy")
## package 'doBy' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\pdmoerland\AppData\Local\Temp\RtmpURMFjN\downloaded_packages
library(doBy)
summaryBy(age~pclass, data=titanic3, FUN=summary)
## pclass age.Min. age.1st Qu. age.Median age.Mean age.3rd Qu. age.Max. age.NA's
## 1 1st 0.9167 28 39 39.15992 50 80 39
## 2 2nd 0.6667 22 29 29.50670 36 70 16
## 3 3rd 0.1667 18 24 24.81637 32 74 208
## Nice graphical summary using summarytools package
install.packages("summarytools")
## package 'lobstr' successfully unpacked and MD5 sums checked
## package 'magick' successfully unpacked and MD5 sums checked
## package 'pryr' successfully unpacked and MD5 sums checked
## package 'rapportools' successfully unpacked and MD5 sums checked
## package 'summarytools' successfully unpacked and MD5 sums checked
##
## The downloaded binary packages are in
## C:\Users\pdmoerland\AppData\Local\Temp\RtmpURMFjN\downloaded_packages
library(summarytools)
view(dfSummary(titanic3))
help(summary)
fit.age <- lm(age ~ pclass, data=titanic3)
summary(fit.age)
##
## Call:
## lm(formula = age ~ pclass, data = titanic3)
##
## Residuals:
## Min 1Q Median 3Q Max
## -38.243 -7.816 -0.816 7.840 49.184
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 39.1599 0.7790 50.269 <2e-16 ***
## pclass2nd -9.6532 1.1257 -8.575 <2e-16 ***
## pclass3rd -14.3436 0.9751 -14.709 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.13 on 1043 degrees of freedom
## (263 observations deleted due to missingness)
## Multiple R-squared: 0.172, Adjusted R-squared: 0.1704
## F-statistic: 108.3 on 2 and 1043 DF, p-value: < 2.2e-16
class(fit.age)
## [1] "lm"
help(summary.lm)
help(descriptive)
## No documentation for 'descriptive' in specified packages and libraries:
## you could try '??descriptive'
#help.search("descriptive statistics") # same as ??descriptive
#RSiteSearch("{descriptive statistics}") # braces to indicate that words are to be searched as one entity
#install.packages("sos")
#library(sos)
#findFn("{descriptive statistics}")
help.search("Student")
help(t.test)
with(titanic3,t.test(age[sex=="male"],age[sex=="female"]))
##
## Welch Two Sample t-test
##
## data: age[sex == "male"] and age[sex == "female"]
## t = 2.0497, df = 798.36, p-value = 0.04072
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 0.08036699 3.71595773
## sample estimates:
## mean of x mean of y
## 30.58523 28.68707
t.test(subset(titanic3,sex=="male")$age,subset(titanic3,sex=="female")$age)
##
## Welch Two Sample t-test
##
## data: subset(titanic3, sex == "male")$age and subset(titanic3, sex == "female")$age
## t = 2.0497, df = 798.36, p-value = 0.04072
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 0.08036699 3.71595773
## sample estimates:
## mean of x mean of y
## 30.58523 28.68707
test.age <- t.test(age ~ sex, data = titanic3)
test.age
##
## Welch Two Sample t-test
##
## data: age by sex
## t = -2.0497, df = 798.36, p-value = 0.04072
## alternative hypothesis: true difference in means between group female and group male is not equal to 0
## 95 percent confidence interval:
## -3.71595773 -0.08036699
## sample estimates:
## mean in group female mean in group male
## 28.68707 30.58523
fit.age <- lm(age ~ pclass, data=titanic3)
fit.age
##
## Call:
## lm(formula = age ~ pclass, data = titanic3)
##
## Coefficients:
## (Intercept) pclass2nd pclass3rd
## 39.160 -9.653 -14.344
summary(fit.age)
##
## Call:
## lm(formula = age ~ pclass, data = titanic3)
##
## Residuals:
## Min 1Q Median 3Q Max
## -38.243 -7.816 -0.816 7.840 49.184
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 39.1599 0.7790 50.269 <2e-16 ***
## pclass2nd -9.6532 1.1257 -8.575 <2e-16 ***
## pclass3rd -14.3436 0.9751 -14.709 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.13 on 1043 degrees of freedom
## (263 observations deleted due to missingness)
## Multiple R-squared: 0.172, Adjusted R-squared: 0.1704
## F-statistic: 108.3 on 2 and 1043 DF, p-value: < 2.2e-16
## output of model is a list
str(fit.age)
## List of 14
## $ coefficients : Named num [1:3] 39.16 -9.65 -14.34
## ..- attr(*, "names")= chr [1:3] "(Intercept)" "pclass2nd" "pclass3rd"
## $ residuals : Named num [1:1046] -10.16 -38.24 -37.16 -9.16 -14.16 ...
## ..- attr(*, "names")= chr [1:1046] "1" "2" "3" "4" ...
## $ effects : Named num [1:1046] -966.41 -6.98 -193.11 -6.64 -11.64 ...
## ..- attr(*, "names")= chr [1:1046] "(Intercept)" "pclass2nd" "pclass3rd" "" ...
## $ rank : int 3
## $ fitted.values: Named num [1:1046] 39.2 39.2 39.2 39.2 39.2 ...
## ..- attr(*, "names")= chr [1:1046] "1" "2" "3" "4" ...
## $ assign : int [1:3] 0 1 1
## $ qr :List of 5
## ..$ qr : num [1:1046, 1:3] -32.3419 0.0309 0.0309 0.0309 0.0309 ...
## .. ..- attr(*, "dimnames")=List of 2
## .. .. ..$ : chr [1:1046] "1" "2" "3" "4" ...
## .. .. ..$ : chr [1:3] "(Intercept)" "pclass2nd" "pclass3rd"
## .. ..- attr(*, "assign")= int [1:3] 0 1 1
## .. ..- attr(*, "contrasts")=List of 1
## .. .. ..$ pclass: chr "contr.treatment"
## ..$ qraux: num [1:3] 1.03 1.02 1.05
## ..$ pivot: int [1:3] 1 2 3
## ..$ tol : num 1e-07
## ..$ rank : int 3
## ..- attr(*, "class")= chr "qr"
## $ df.residual : int 1043
## $ na.action : 'omit' Named int [1:263] 16 38 41 47 60 70 71 75 81 107 ...
## ..- attr(*, "names")= chr [1:263] "16" "38" "41" "47" ...
## $ contrasts :List of 1
## ..$ pclass: chr "contr.treatment"
## $ xlevels :List of 1
## ..$ pclass: chr [1:3] "1st" "2nd" "3rd"
## $ call : language lm(formula = age ~ pclass, data = titanic3)
## $ terms :Classes 'terms', 'formula' language age ~ pclass
## .. ..- attr(*, "variables")= language list(age, pclass)
## .. ..- attr(*, "factors")= int [1:2, 1] 0 1
## .. .. ..- attr(*, "dimnames")=List of 2
## .. .. .. ..$ : chr [1:2] "age" "pclass"
## .. .. .. ..$ : chr "pclass"
## .. ..- attr(*, "term.labels")= chr "pclass"
## .. ..- attr(*, "order")= int 1
## .. ..- attr(*, "intercept")= int 1
## .. ..- attr(*, "response")= int 1
## .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
## .. ..- attr(*, "predvars")= language list(age, pclass)
## .. ..- attr(*, "dataClasses")= Named chr [1:2] "numeric" "factor"
## .. .. ..- attr(*, "names")= chr [1:2] "age" "pclass"
## $ model :'data.frame': 1046 obs. of 2 variables:
## ..$ age : num [1:1046] 29 0.917 2 30 25 ...
## ..$ pclass: Factor w/ 3 levels "1st","2nd","3rd": 1 1 1 1 1 1 1 1 1 1 ...
## ..- attr(*, "terms")=Classes 'terms', 'formula' language age ~ pclass
## .. .. ..- attr(*, "variables")= language list(age, pclass)
## .. .. ..- attr(*, "factors")= int [1:2, 1] 0 1
## .. .. .. ..- attr(*, "dimnames")=List of 2
## .. .. .. .. ..$ : chr [1:2] "age" "pclass"
## .. .. .. .. ..$ : chr "pclass"
## .. .. ..- attr(*, "term.labels")= chr "pclass"
## .. .. ..- attr(*, "order")= int 1
## .. .. ..- attr(*, "intercept")= int 1
## .. .. ..- attr(*, "response")= int 1
## .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
## .. .. ..- attr(*, "predvars")= language list(age, pclass)
## .. .. ..- attr(*, "dataClasses")= Named chr [1:2] "numeric" "factor"
## .. .. .. ..- attr(*, "names")= chr [1:2] "age" "pclass"
## ..- attr(*, "na.action")= 'omit' Named int [1:263] 16 38 41 47 60 70 71 75 81 107 ...
## .. ..- attr(*, "names")= chr [1:263] "16" "38" "41" "47" ...
## - attr(*, "class")= chr "lm"
names(fit.age)
## [1] "coefficients" "residuals" "effects" "rank"
## [5] "fitted.values" "assign" "qr" "df.residual"
## [9] "na.action" "contrasts" "xlevels" "call"
## [13] "terms" "model"
summary(fit.age$residuals)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -38.2432 -7.8164 -0.8164 0.0000 7.8401 49.1836
## or
summary(resid(fit.age))
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -38.2432 -7.8164 -0.8164 0.0000 7.8401 49.1836
hist(resid(fit.age))
coef(fit.age)
## (Intercept) pclass2nd pclass3rd
## 39.159918 -9.653213 -14.343551
predict(fit.age, newdata=data.frame(pclass=factor(levels(titanic3$pclass))))
## 1 2 3
## 39.15992 29.50670 24.81637
update(fit.age,. ~ .+sex)
##
## Call:
## lm(formula = age ~ pclass + sex, data = titanic3)
##
## Coefficients:
## (Intercept) pclass2nd pclass3rd sexmale
## 37.182 -9.927 -14.957 3.720
## the output has a specific class, in this case lm
class(fit.age)
## [1] "lm"
## which functions have been written for this class?
help(methods)
methods(class="lm")
## [1] add1 alias anova case.names coerce
## [6] confint cooks.distance deviance dfbeta dfbetas
## [11] drop1 dummy.coef effects esticon extractAIC
## [16] family formula fortify hatvalues influence
## [21] initialize kappa labels linest logLik
## [26] model.frame model.matrix nobs plot predict
## [31] print proj qr residuals rstandard
## [36] rstudent show simulate slotsFromS3 summary
## [41] variable.names vcov
## see '?methods' for accessing help and source code
## we want to know what the summary function does with an object of class lm
help(summary) # does not give the desired help file
## we need to consult the help file for summary.lm
methods(summary)
## [1] summary,ANY-method summary,diagonalMatrix-method
## [3] summary,sparseMatrix-method summary.aov
## [5] summary.aovlist* summary.aspell*
## [7] summary.check_packages_in_dir* summary.connection
## [9] summary.data.frame summary.Date
## [11] summary.default summary.Duration*
## [13] summary.ecdf* summary.esticon_class*
## [15] summary.factor summary.ggplot*
## [17] summary.glm summary.hcl_palettes*
## [19] summary.infl* summary.Interval*
## [21] summary.linest_class* summary.linest_matrix_class*
## [23] summary.lm summary.lmBy*
## [25] summary.loess* summary.loglm*
## [27] summary.manova summary.matrix
## [29] summary.microbenchmark* summary.mlm*
## [31] summary.model_stability_glm_class* summary.negbin*
## [33] summary.nls* summary.packageStatus*
## [35] summary.Period* summary.polr*
## [37] summary.POSIXct summary.POSIXlt
## [39] summary.ppr* summary.prcomp*
## [41] summary.princomp* summary.proc_time
## [43] summary.rlang:::list_of_conditions* summary.rlang_error*
## [45] summary.rlang_message* summary.rlang_trace*
## [47] summary.rlang_warning* summary.rlm*
## [49] summary.section_function* summary.shingle*
## [51] summary.srcfile summary.srcref
## [53] summary.stepfun summary.stl*
## [55] summary.table summary.trellis*
## [57] summary.tukeysmooth* summary.vctrs_sclr*
## [59] summary.vctrs_vctr* summary.warnings
## see '?methods' for accessing help and source code
help(summary.lm)
plot(fit.age)
plot(age ~ fare, data=titanic3)
## the type of plot is automatically adapted to the type of variable
plot(age~pclass, data=titanic3)
x <- 10
z <- if (x < 2) 4 else 3
z
## [1] 3
# Or more interesting from the function that we wrote earlier
work <- FALSE
if(work==TRUE){
cat("wake up")
} else{
cat("you can stay in bed")
}
## you can stay in bed
A <- matrix(1:10, 2, 5)
rownames(A) <- c("gene1", "gene2")
colnames(A) <- c("sample1", "sample2", "sample3","sample4", "sample5")
results <- numeric(2)
results
## [1] 0 0
for (i in 1:2) {
results[i] <- mean(A[i, ])
}
results
## [1] 5 6
apply(A, 1, mean)
## gene1 gene2
## 5 6
titanic3 <- read.dta("Exercises/titanic3.dta", convert.underscore=TRUE)
head(titanic3[,c("fare","pclass")])
## fare pclass
## 1 211.3375 1st
## 2 151.5500 1st
## 3 151.5500 1st
## 4 151.5500 1st
## 5 151.5500 1st
## 6 26.5500 1st
with(titanic3,tapply(fare, pclass, mean,na.rm=T))
## 1st 2nd 3rd
## 87.50899 21.17920 13.30289
# Solution using the dplyr package
#install.packages("dplyr")
library(dplyr)
summarise(group_by(titanic3, pclass), mean(fare,na.rm=TRUE))
## # A tibble: 3 x 2
## pclass `mean(fare, na.rm = TRUE)`
## <fct> <dbl>
## 1 1st 87.5
## 2 2nd 21.2
## 3 3rd 13.3