render compile
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
---
|
||||
title: "Lesson 6"
|
||||
format: html
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
```{r}
|
||||
|
||||
https://rs1.drwater.net
|
||||
|
||||
username:
|
||||
- ruser01
|
||||
- ruser02
|
||||
- ruser03
|
||||
- ruser04
|
||||
- ruser05
|
||||
- ruser06
|
||||
|
||||
RWEP2025
|
||||
|
||||
```
|
||||
|
||||
|
||||
# 安装包
|
||||
|
||||
|
||||
```{r}
|
||||
install.packages("tidyverse")
|
||||
|
||||
x <- c(1:10, NA)
|
||||
|
||||
hist(x)
|
||||
|
||||
mean(x, na.rm = TRUE)
|
||||
|
||||
median(x, na.rm = TRUE)
|
||||
|
||||
sd(x, na.rm = TRUE)
|
||||
|
||||
|
||||
for(i in 1:10){
|
||||
print(i)
|
||||
}
|
||||
|
||||
|
||||
x + y + x * y
|
||||
|
||||
myfunc <- function(x, y = 3) {
|
||||
x + y + x * y
|
||||
}
|
||||
|
||||
|
||||
myfunc(1, 2)
|
||||
|
||||
|
||||
myfunc(10)
|
||||
|
||||
|
||||
c(FALSE, 2, 1:3, 3)
|
||||
|
||||
c(FALSE, 2, 1:3, 3) > 1
|
||||
|
||||
all(c(FALSE, 2, 1:3, 3) > 1)
|
||||
|
||||
|
||||
c(1L,2L,3L)
|
||||
|
||||
any(c(FALSE, 2, 1:3, 3) > 1)
|
||||
|
||||
|
||||
x <- 10
|
||||
|
||||
sin(x) = ?
|
||||
|
||||
paste("sin(x) = ", sin(x), sep = " ")
|
||||
|
||||
paste0("sin(x) = ", sin(x))
|
||||
|
||||
|
||||
substr("Monday", 1, 3)
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
# tidy
|
||||
|
||||
|
||||
```{r}
|
||||
require(readxl)
|
||||
|
||||
aqdf <-readxl::read_xlsx("../../data/airquality.xlsx", sheet = "metadf")
|
||||
|
||||
# install.packages("skimr")
|
||||
|
||||
aqdf |>
|
||||
skimr::skim()
|
||||
|
||||
# base
|
||||
|
||||
# tidyverse
|
||||
|
||||
aqdf |>
|
||||
dplyr::group_by(Area) |>
|
||||
dplyr::summarize(
|
||||
n = n(),
|
||||
lon.mean = mean(lon, na.rm = TRUE),
|
||||
lon.sd = sd(lat, na.rm = TRUE)
|
||||
) |>
|
||||
dplyr::filter(Area %in% c("北京市", "天津市", "上海市", "重庆市")) |>
|
||||
ggplot(aes(x = n, y = lon.mean)) +
|
||||
geom_point() +
|
||||
geom_line() +
|
||||
geom_errorbar(
|
||||
aes(ymin = lon.mean - lon.sd,
|
||||
ymax = lon.mean + lon.sd)
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
readxl::read_xlsx("./airquality.xlsx")
|
||||
|
||||
flights|>
|
||||
filter(dest=="IAH")|>
|
||||
group_by(year,month,day)|>summarize(n=n(),
|
||||
delay=mean(arr_delay,na.rm=TRUE))|>filter(n>10)
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user