forked from tpemartin/110-1-r4ds-main
-
Notifications
You must be signed in to change notification settings - Fork 0
/
11.2
103 lines (80 loc) · 2 KB
/
11.2
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
---
title: '11.2'
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
```{r}
JohnsFamily <-
list(
name = "John",
age = 35,
spouse = list(
name = "Mary",
age = 32),
children = list(
list(
name = "Bill",
age = 5),
list(
name = "Jane",
age = 3)
)
)
```
```{r}
JohnsFamilyCopy <- JohnsFamily
JohnsFamilyCopy[[1]] <- "Watson"
JohnsFamilyCopy[[1]]
```
```{r}
JohnsFamilyCopy[c(1,2)] <-
list(name="Watson", age=37)
JohnsFamilyCopy[c(1,2)]
```
```{r}
JohnsFamilyCopy[c(1,2)] <-
list("Dickens", 32)
JohnsFamilyCopy[c(1,2)]
```
```{r}
JohnsFamilyCopy$spouse[["age"]]
JohnsFamilyCopy$children[[1]]$name
```
```{r}
example1 <- c("John", "Mary", "Bill")
# retrieve an non-existing element name "person4"
example1[["person4"]] <- "Ken"
# retrieve two non-existing element positions
example1[c(7,8)] <- c("Jack", "Janem")
example1
```
```{r}
JohnsFamilyCopy2 <- JohnsFamily
# Add a new born
JohnsFamilyCopy2$children[[3]] <-
list(name="Lisa", age=0) # $ is for list only
JohnsFamilyCopy2
```
```{r}
JohnsFamilyCopy3 <- JohnsFamily
JohnsFamilyCopy3$children[3] <-
list(
name = "Jimmy",
age = 0
)
JohnsFamilyCopy3
```