- Access data
- Build models
- Test hypotheses
- Run analyses
- Report the results
- Share the results and the techniques with others
?formula
?factor ?ordered ?levels
head(mtcars)
```{R, eval = FALSE} ?data.frame ?read.csv ?read.table
## How do we subset vectors? ```{R} vec <- c(1, 2, 3) vec[vec > 2]
vec <- 1:3 vec > 2
vec <- seq(from = 1, to = 3) subs <- c(T, F, T) vec[subs]
df <- data.frame(val = c(1, 2, 3), other = c("a", "b", "a")) df$other
df[df$other == "b", ]
subset(df, val == 1)
But these things are constantly evolving: ```{R, message = FALSE} library(dplyr) df %>% filter(other == "b")
```{R} mtcars %>% filter(mpg > 20) %>% filter(carb >= 4)
plot(c(1, 2, 3), c(1, 2, 1)) lines(c(1, 2, 3), c(2, 1, 2))
Again, there are much more sophisticated ways, as you know... e.g. ```{R, message = FALSE} library(ggplot2) mtcars %>% ggplot(aes(wt, mpg)) + geom_point() + geom_smooth()
## How do we save to disk? ```{R, eval = FALSE} png("out.png") plot(c(1, 2, 3), c(1, 2, 1), type = "l") dev.off()
```{R, eval = FALSE} ?pdf ?png ?Devices
## How do we save to disk? Again, using ggplot2... ```{R, eval = FALSE} g <- mtcars %>% ggplot(aes(wt, mpg)) + geom_point() + geom_smooth() ggsave("out.png", g)
```{R, eval = FALSE} ?ggsave
## How do we use packages? Install it first: ```{R, eval = FALSE} install.packages(c("tibble"))
or from RStudio menus, and then use it:
```{R, eval = FALSE} library(tibble)
not forgetting: ```{R, eval = FALSE} update.packages()
occasionally.
Learn how to:
- Write code
- Write documentation
- So you can come back and understand it later
- Identify and isolate reusable code
- So you don’t have to write it again later
- Generate documented results
- Read and understand other people's code
"I honestly didn't think you could even USE emoji in variable names. Or that there were so many different crying ones."
https://imgs.xkcd.com/comics/code_quality.png
- Read and write well-documented and well-structured code
- Use this to generate clear and well-documented results/reports
- Problems will be structured around population dynamics, epidemiology and biodiversity
- They will start off easy and ramp up
- Packages (libraries) will allow you to solve many problems easily, but we are focusing on problems they don’t help with!
http://phdcomics.com/comics/archive.php?comicid=946
and optionally:
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.