-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chapter_14.Rmd
50 lines (32 loc) · 1.2 KB
/
Chapter_14.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
---
title: "Chapter 14"
author: "Laura"
date: "12/11/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, cache = TRUE)
library(tidyverse); library(skimr); library(nycflights13); library(GGally); library(ggstance); library(lvplot); library(hexbin); library(modelr); library(magrittr); library(maps); library(stringr); library(htmlwidgets)
```
## Notes for Chapter 14 Strings
### 14.1 Introduction
This chapter will focus on the stringr package for string manipulation. stringr is not part of the core tidyverse because you don’t always have textual data, so we need to load it explicitly.
### 14.2 String basics
Beware that the printed representation of a string is not the same as string itself, because the printed representation shows the escapes. To see the raw contents of the string, use writeLines():
```{r ch1421}
x <- c("\"", "\\")
x
writeLines(x)
print(x) # equivalent to line 27, x
?"'" #for help with special characters
```
Functions from stringr start with `str_`
```{r ch1422}
x <- c("Apple", "Banana", "Pear")
str_sub(x, 2, -2)
```
### 14.3 Matching patterns with regular expressions
```{r ch1431}
x <- c("apple", "banana", "pear")
str_view(x, "an")
```