July 24, 2019
Instructor: Andy Hong, PhD
Lead Urban Health Scientist
The George Institute for Global Health
University of Oxford
install.packages("ggplot2")
library(ggplot2)
> x = c(1, 5, 4, 9, 0)
>
> length(x)
[1] 5
>
> x = c(1, 5.4, TRUE, "hello")
>
> x
[1] "1" "5.4" "TRUE" "hello"
> x = list(1, 2)
> x
[[1]]
[1] 1
[[2]]
[1] 2
>
> x = list("new","class")
> x
[[1]]
[1] "new"
[[2]]
[1] "class"
> x = data.frame(column1=c(1,2,3), column2=c("A","B","C"))
> x
column1 column2
1 1 A
2 2 B
3 3 C
> str(x)
'data.frame': 3 obs. of 2 variables:
$ column1: num 1 2 3
$ column2: Factor w/ 3 levels "A","B","C": 1 2 3
> head(x)
column1 column2
1 1 A
2 2 B
3 3 C
> View(x) # Note "V" is capitalized
# Testing for equality in R using ==
> x = 1
> if(x == 1) cat("x is 1!") else cat("x is not 1!")
x is 1!
# Boolean algebra: TRUE/FALSE statements and math operators:
< means "less than"
<= means "less than or equal"
>= means "more than or equal"
!= "not equal to"
# Logical operators:
& means “and”
| means “or”