2024-03-25 21:48:30 +08:00
|
|
|
|
---
|
2024-04-09 00:37:12 +08:00
|
|
|
|
title: "大数据分析工具"
|
2024-03-25 21:48:30 +08:00
|
|
|
|
subtitle: 《区域水环境污染数据分析实践》<br>Data analysis practice of regional water environment pollution
|
|
|
|
|
author: 苏命、王为东<br>中国科学院大学资源与环境学院<br>中国科学院生态环境研究中心
|
|
|
|
|
date: today
|
|
|
|
|
lang: zh
|
|
|
|
|
format:
|
|
|
|
|
revealjs:
|
|
|
|
|
theme: dark
|
|
|
|
|
slide-number: true
|
|
|
|
|
chalkboard:
|
|
|
|
|
buttons: true
|
|
|
|
|
preview-links: auto
|
|
|
|
|
lang: zh
|
|
|
|
|
toc: true
|
|
|
|
|
toc-depth: 1
|
|
|
|
|
toc-title: 大纲
|
|
|
|
|
logo: ./_extensions/inst/img/ucaslogo.png
|
|
|
|
|
css: ./_extensions/inst/css/revealjs.css
|
|
|
|
|
pointer:
|
|
|
|
|
key: "p"
|
|
|
|
|
color: "#32cd32"
|
|
|
|
|
pointerSize: 18
|
|
|
|
|
revealjs-plugins:
|
|
|
|
|
- pointer
|
|
|
|
|
filters:
|
|
|
|
|
- d2
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
```{r}
|
|
|
|
|
#| echo: false
|
|
|
|
|
knitr::opts_chunk$set(echo = TRUE)
|
|
|
|
|
source("../../coding/_common.R")
|
|
|
|
|
library(nycflights13)
|
|
|
|
|
library(tidyverse)
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 匹配数字
|
|
|
|
|
|
|
|
|
|
### 匹配数字:
|
|
|
|
|
|
|
|
|
|
- \d:匹配任意数字字符。
|
|
|
|
|
- \d+:匹配一个或多个数字字符。
|
|
|
|
|
- [0-9]: 匹配数字
|
|
|
|
|
|
|
|
|
|
### 匹配字母:
|
|
|
|
|
|
|
|
|
|
- \w:匹配任意字母、数字或下划线字符。
|
|
|
|
|
- \w+:匹配一个或多个字母、数字或下划线字符。
|
|
|
|
|
|
|
|
|
|
## 匹配数字
|
|
|
|
|
|
|
|
|
|
### 匹配空白字符:
|
|
|
|
|
|
|
|
|
|
- \s:匹配任意空白字符,包括空格、制表符、换行符等。
|
|
|
|
|
- \s+:匹配一个或多个空白字符。
|
|
|
|
|
|
|
|
|
|
### 匹配特定字符:
|
|
|
|
|
|
|
|
|
|
- [abc]:匹配字符 a、b 或 c 中的任意一个。
|
|
|
|
|
- [a-z]:匹配任意小写字母。
|
|
|
|
|
- [A-Z]:匹配任意大写字母。
|
|
|
|
|
- [0-9]:匹配任意数字。
|
|
|
|
|
|
|
|
|
|
## 匹配数字
|
|
|
|
|
|
|
|
|
|
### 匹配重复次数:
|
|
|
|
|
|
|
|
|
|
- {n}:匹配前一个字符恰好 n 次。
|
|
|
|
|
- {n,}:匹配前一个字符至少 n 次。
|
|
|
|
|
- {n,m}:匹配前一个字符至少 n 次,但不超过 m 次。
|
|
|
|
|
|
|
|
|
|
### 匹配边界:
|
|
|
|
|
|
|
|
|
|
- ^:匹配字符串的开头。
|
|
|
|
|
- $:匹配字符串的结尾。
|
|
|
|
|
|
|
|
|
|
## 匹配数字
|
|
|
|
|
|
|
|
|
|
### 匹配特殊字符:
|
|
|
|
|
|
|
|
|
|
- \:转义特殊字符,使其按字面意义匹配。
|
|
|
|
|
- .:匹配任意单个字符。
|
|
|
|
|
- |:表示“或”关系,匹配两个或多个表达式之一。
|
|
|
|
|
|
|
|
|
|
#### 匹配次数:
|
|
|
|
|
|
|
|
|
|
- *:匹配前一个字符零次或多次。
|
|
|
|
|
- +:匹配前一个字符一次或多次。
|
|
|
|
|
- ?:匹配前一个字符零次或一次。
|
|
|
|
|
|
|
|
|
|
## 匹配数字
|
|
|
|
|
|
|
|
|
|
### 分组和捕获:
|
|
|
|
|
|
|
|
|
|
- ():将一系列模式组合成一个单元,可与特殊字符一起使用。
|
|
|
|
|
|
|
|
|
|
### 预定义字符集:
|
|
|
|
|
|
|
|
|
|
- \d:任意数字,相当于 [0-9]。
|
|
|
|
|
- \w:任意字母、数字或下划线字符,相当于 [a-zA-Z0-9_]。
|
|
|
|
|
- \s:任意空白字符,相当于 [ \t\n\r\f\v]。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 实例
|
|
|
|
|
|
|
|
|
|
```{r}
|
|
|
|
|
library(babynames)
|
|
|
|
|
(x <- c("apple", "apppple", "abc123def"))
|
|
|
|
|
x[str_detect(x, "[0-9]")]
|
|
|
|
|
x[str_detect(x, "abc[0-9]+")]
|
|
|
|
|
x[str_detect(x, "pp")]
|
|
|
|
|
x[str_detect(x, "p{4}")]
|
|
|
|
|
x[str_detect(x, "p{4}")]
|
|
|
|
|
x[str_detect("apple", "ap*")]
|
|
|
|
|
x[str_detect("apple", "app*")]
|
|
|
|
|
x[str_detect("apple", "a..le")]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 练习
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
找出`babyname`中名字含有ar的行
|
|
|
|
|
|
|
|
|
|
```{r}
|
|
|
|
|
#| echo: false
|
|
|
|
|
babynames |>
|
|
|
|
|
filter(str_detect(name, "ar"))
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 练习
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
找出`babyname`中名字含有ar或者以ry结尾的行。
|
|
|
|
|
|
|
|
|
|
```{r}
|
|
|
|
|
#| echo: false
|
|
|
|
|
babynames |>
|
|
|
|
|
filter(str_detect(name, "ar"))
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![](../../image/data-science/transform.png)
|
|
|
|
|
|
|
|
|
|
|
2024-04-09 00:37:12 +08:00
|
|
|
|
## GNU/Linux服务器
|
|
|
|
|
|
|
|
|
|
- `ssh`, `scp`
|
|
|
|
|
- `bash`
|
|
|
|
|
- grep
|
|
|
|
|
- sed
|
|
|
|
|
- awk
|
|
|
|
|
- find
|
|
|
|
|
- xargs
|
|
|
|
|
- `Editor`
|
|
|
|
|
- `Virtual Studio Code`
|
|
|
|
|
- `Vim`
|
|
|
|
|
- `Emacs`
|
|
|
|
|
|
2024-03-25 21:48:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 欢迎讨论!{.center}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
`r rmdify::slideend(wechat = FALSE, type = "public", tel = FALSE, thislink = "https://drwater.rcees.ac.cn/course/public/RWEP/@PUB/SD/")`
|
|
|
|
|
|