-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathHands On Programming - Exercises.Rmd
2561 lines (1898 loc) · 45.6 KB
/
Hands On Programming - Exercises.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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Hand On Programming with R"
subtitle: "Code & Exercises"
author: "Josue Mendoza"
output:
html_document:
theme: "cerulean"
highlight: tango
toc: true
toc_depth: 5
toc_float: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(message = FALSE, error = TRUE)
```
# Part I. Project 1: Weighted Dice
## Chapter 1. The Very Basics
### The R User Interface
```{r error=TRUE}
1 + 1
100:130
5 - +1
3 % 5
2 * 3
4 - 1
6 / (4 - 1)
```
##### Exercise 1.1 (p. 6 - 7)
That’s the basic interface for executing R code in RStudio. Think you have it? If so, try doing these simple tasks. If you execute everything correctly, you should end up with the same number that you started with:
1. Choose any number and add 2 to it.
```{r}
19 # Number choosed
19 + 2
```
2. Multiply the result by 3.
```{r}
21 * 3
```
3. Subtract 6 from the answer.
```{r}
63 - 6
```
4. Divide what you get by 3.
```{r}
57 / 3
```
### Objects
```{r error=TRUE}
a <- 1
a
a + 2
die <- 1:6
die
Name <- 1
name <- 0
Name + 1
my_number <- 1
my_number
my_number <- 999
my_number
die - 1
die / 2
die * die
1:2
1:4
die
die + 1:2
die + 1:4
die %*% die
die %o% die
```
### Functions
```{r error=TRUE}
round(3.1415)
factorial(3)
mean(1:6)
mean(die)
round(mean(die))
sample(x = 1:4, size = 2)
sample(x = die, size = 1)
sample(x = die, size = 1)
sample(x = die, size = 1)
sample(die, size = 1)
round(3.1415, corners = 2)
args(round)
round(3.1415, digits = 2)
sample(die, 1)
sample(size = 1, x = die)
```
### Sample with Replacement
```{r error=TRUE}
sample(die, size = 2)
sample(die, size = 2, replace = TRUE)
sample(die, size = 2, replace = TRUE)
dice <- sample(die, size = 2, replace = TRUE)
dice
sum(dice)
dice
dice
dice
```
### Writing Your Functions
```{r error=TRUE}
die <- 1:6
dice <- sample(die, size = 2, replace = TRUE)
sum(dice)
```
```
my_function <- function() {}
```
```{r error=TRUE}
roll <- function() {
die <- 1:6
dice <- sample(die, size = 2, replace = TRUE)
sum(dice)
}
roll()
roll
dice
1 + 1
sqrt(2)
dice <- sample(die, size = 2, replace = TRUE)
two <- 1 + 1
a <- sqrt(2)
```
#### Arguments
```{r error=TRUE}
roll2 <- function() {
dice <- sample(bones, size = 2, replace = TRUE)
sum(dice)
}
roll2()
roll2 <- function(bones) {
dice <- sample(bones, size = 2, replace = TRUE)
sum(dice)
}
roll2(bones = 1:4)
roll2(bones = 1:6)
roll2(1:20)
roll2()
roll2 <- function(bones = 1:6) {
dice <- sample(bones, size = 2, replace = TRUE)
sum(dice)
}
roll2()
```
## Chapter 2. Packages and Help Pages
### Packages
```{r eval=FALSE}
install.packages("ggplot2")
```
```{r error=TRUE}
qplot
library("ggplot2")
qplot
x <- c(-1, -0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6, 0.8, 1)
x
y <- x ^ 3
y
qplot(x, y)
x <- c(1, 2, 2, 2, 3, 3)
qplot(x, binwidth = 1)
x2 <- c(1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4)
qplot(x2, binwidth = 1)
```
##### Exercise 2.1 (p. 27)
Let x3 be the following vector:
```
x3 <- c(0, 1, 1, 2, 2, 2, 3, 3, 4)
```
Imagine what a histogram of `x3` would look like. Assume that the histogram has a bin width of 1. How many bars will the histogram have? Where will they appear? How high will each be?
When you are done, plot a histogram of x3 with binwidth = 1, and see if you are right.
```{r}
library(ggplot2)
x3 <- c(0, 1, 1, 2, 2, 2, 3, 3, 4)
qplot(x3, binwidth = 1)
```
***
```{r}
replicate(3, 1 + 1)
replicate(10, roll())
rolls <- replicate(10000, roll())
qplot(rolls, binwidth = 1)
```
### Getting Help with Help Pages
```{r}
?sqrt
?log10
?sample
??log
```
##### Exercise 2.2 (p. 32)
Rewrite the roll function to roll a pair of weighted dice:
```
roll <- function() {
die <- 1:6
dice <- sample(die, size = 2, replace = TRUE)
sum(dice)
}
```
You will need to add a prob argument to the sample function inside of roll. This argument should tell sample to sample the numbers one through five with probability 1/8 and the number 6 with probability 3/8.
When you are finished, read on for a model answer.
```{r}
roll <- function() {
die <- 1:6
dice <- sample(die, size = 2, replace = TRUE, prob = c(1/8, 1/8, 1/8, 1/8, 1/8, 3/8))
sum(dice)
}
rolls <- replicate(10000, roll())
qplot(rolls, binwidth = 1)
```
# Part II. Project 2: Playing Cards
## Chapter 3. R Objects
### Atomic Vectors
```{r}
die <- c(1, 2, 3, 4, 5, 6)
die
is.vector(die)
five <- 5
five
is.vector(five)
length(five)
length(die)
int <- 1L
text <- "ace"
int <- c(1L, 5L)
text <- c("ace", "hearts")
sum(num)
sum(text)
```
#### Doubles
```{r}
die <- c(1, 2, 3, 4, 5, 6)
die
typeof(die)
```
#### Integers
```{r}
int <- c(-1L, 2L, 4L)
int
typeof(int)
sqrt(2)^2 - 2
```
#### Characters
```{r}
text <- c("Hello", "World")
text
typeof(text)
typeof("Hello")
```
##### Exercise 3.1 (p. 41)
Can you spot the difference between a character string and a number? Here’s a test: Which of these are character strings and which are numbers? 1, "1", "one".
Only the first one, which is not surrounded by quotation marks.
#### Logicals
```{r}
3 > 4
logic <- c(TRUE, FALSE, TRUE)
logic
typeof(logic)
typeof(F)
```
#### Complex and Raw
```{r}
comp <- c(1 + 1i, 1 + 2i, 1 + 3i)
comp
typeof(comp)
raw(3)
typeof(raw(3))
```
##### Exercise 3.2 (p. 43)
Create an atomic vector that stores just the face names of the cards in a royal flush, for example, the ace of spades, king of spades, queen of spades, jack of spades, and ten of spades. The face name of the ace of spades would be “ace,” and “spades” is the suit.
Which type of vector will you use to save the names?
Charcater vector because are names.
```{r}
hand <- c("ace", "king", "queen", "jack", "ten")
hand
typeof(head)
```
### Attributes
```{r}
attributes(die)
```
#### Names
```{r}
names(die)
names(die) <- c("one", "two", "three", "four", "five", "six")
names(die)
attributes(die)
die
die + 1
names(die) <- c("uno", "dos", "tres", "quatro", "cinco", "seis")
die
names(die) <- NULL
die
```
#### Dim
```{r}
dim(die) <- c(2, 3)
die
dim(die) <- c(3, 2)
die
dim(die) <- c(1, 2, 3)
die
```
### Matrices
```{r}
m <- matrix(die, nrow = 2)
m
m <- matrix(die, nrow = 2, byrow = TRUE) # fill the matrix row by row
m
```
### Arrays
```{r}
ar <- array(c(11:14, 21:24, 31:34), dim = c(2, 2, 3))
ar
```
##### Exercise 3.3 (p. 47)
Create the following matrix, which stores the name and suit of every card in a royal flush.
## [,1] [,2]
## [1,] "ace" "spades"
## [2,] "king" "spades"
## [3,] "queen" "spades"
## [4,] "jack" "spades"
## [5,] "ten" "spades"
```{r}
card_names <- c("ace", "king", "queen", "jack", "ten")
spades <- rep("spades", 5)
matrix(c(card_names, spades), ncol = 2)
```
```{r}
hand1 <- c("ace", "king", "queen", "jack", "ten", "spades", "spades",
"spades", "spades", "spades")
matrix(hand1, nrow = 5)
matrix(hand1, ncol = 2)
dim(hand1) <- c(5, 2)
hand2 <- c("ace", "spades", "king", "spades", "queen", "spades", "jack",
"spades", "ten", "spades")
matrix(hand2, nrow = 5, byrow = TRUE)
matrix(hand2, ncol = 2, byrow = TRUE)
```
### Class
```{r}
dim(die) <- c(2, 3)
typeof(die)
class(die)
attributes(die)
class("Hello")
class(5)
```
#### Dates and Times
```{r}
now <- Sys.time()
now
typeof(now)
class(now)
unclass(now)
mil <- 1000000
mil
class(mil) <- c("POSIXct", "POSIXt")
mil
```
#### Factors
```{r}
gender <- factor(c("male", "female", "female", "male"))
typeof(gender)
attributes(gender)
unclass(gender)
gender
as.character(gender)
```
##### Exercise 3.4 (p. 51)
Many card games assign a numerical value to each card. For example, in blackjack, each face card is worth 10 points, each number card is worth between 2 and 10 points, and each ace is worth 1 or 11 points, depending on the final score.
Make a virtual playing card by combining “ace,” “heart,” and 1 into a vector. What type of atomic vector will result? Check if you are right.
```{r}
cards <- c("ace", "hearth", 1)
cards
typeof(cards)
```
### Coercion
```{r}
sum(c(TRUE, TRUE, FALSE, FALSE))
sum(c(1, 1, 0, 0))
as.character(1)
as.logical(1)
as.numeric(FALSE)
```
### Lists
```{r}
list1 <- list(100:130, "R", list(TRUE, FALSE))
list1
```
##### Exercise 3.5 (p. 54)
Use a list to store a single playing card, like the ace of hearts, which has a point value of one. The list should save the face of the card, the suit, and the point value in separate elements.
```{r}
list("ace", "hearts", 1)
```
### Data Frames
```{r}
df <- data.frame(face = c("ace", "two", "six"),
suit = c("clubs", "clubs", "clubs"), value = c(1, 2, 3))
df
typeof(df)
class(df)
str(df)
df <- data.frame(face = c("ace", "two", "six"),
suit = c("clubs", "clubs", "clubs"), value = c(1, 2, 3), stringsAsFactors = FALSE)
deck <- data.frame(
face = c("king", "queen", "jack", "ten", "nine", "eight", "seven", "six",
"five", "four", "three", "two", "ace", "king", "queen", "jack", "ten",
"nine", "eight", "seven", "six", "five", "four", "three", "two", "ace",
"king", "queen", "jack", "ten", "nine", "eight", "seven", "six", "five",
"four", "three", "two", "ace", "king", "queen", "jack", "ten", "nine",
"eight", "seven", "six", "five", "four", "three", "two", "ace"),
suit = c("spades", "spades", "spades", "spades", "spades", "spades",
"spades", "spades", "spades", "spades", "spades", "spades", "spades",
"clubs", "clubs", "clubs", "clubs", "clubs", "clubs", "clubs", "clubs",
"clubs", "clubs", "clubs", "clubs", "clubs", "diamonds", "diamonds",
"diamonds", "diamonds", "diamonds", "diamonds", "diamonds", "diamonds",
"diamonds", "diamonds", "diamonds", "diamonds", "diamonds", "hearts",
"hearts", "hearts", "hearts", "hearts", "hearts", "hearts", "hearts",
"hearts", "hearts", "hearts", "hearts", "hearts"),
value = c(13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
)
```
### Loading Data
```{r}
library(readr)
deck <- read_csv("~/Desktop/Estadística/tidyverse/(2014) Hands-On Programming with R_ Write Your Own Functions and Simulations/Exercises/deck.csv")
head(deck)
```
### Saving Data
```{r}
write.csv(deck, file = "cards.csv", row.names = FALSE)
```
## Chapter 4. Notation
### Selecting Values
`deck[row(s), column(s)]`
#### Positive Integers
```{r}
head(deck)
deck[1, 1]
deck[1, c(1, 2, 3)]
new <- deck[1, c(1, 2, 3)]
new
deck[c(1, 1), c(1, 2, 3)]
vec <- c(6,1,3,6,10,5)
vec[1:3]
deck[1:2, 1:2]
deck[1:2, 1]
deck[1:2, 1, drop = FALSE]
```
#### Negative Integers
```{r}
deck[-(2:52), 1:3]
deck[c(-1, 1), 1]
deck[-1, 1]
```
#### Zero
```{r}
deck[0, 0]
```
#### Blank Spaces
```{r}
deck[1, ]
```
#### Logical Values
```{r}
deck[1, c(TRUE, TRUE, FALSE)]
rows <- c(TRUE, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F)
## Only prints "TRUEs"
deck[rows, ]
```
#### Names
```{r}
deck[1, c("face", "suit", "value")]
deck[ , "value"]
```
### Deal a Card
##### Exercise 4.1 (p. 70)
Complete the following code to make a function that returns the first row of a data frame:
```
deal <- function(cards) {
#?
}
```
```{r}
deal <- function(cards){
cards[1, ]
}
deal(deck)
```
### Shuffle the Deck
```{r}
deck2 <- deck[1:52, ]
head(deck2)
deck3 <- deck[c(2, 1, 3:52), ]
head(deck3)
random <- sample(1:52, size = 52)
random
deck4 <- deck[random, ]
head(deck4)
```
##### Exercise 4.2 (p. 73)
Use the preceding ideas to write a shuffle function. shuffle should take a data frame and return a shuffled copy of the data frame.
```{r}
## My solution
shuffle_df <- function(df){
random <- sample(1:nrow(df), size = nrow(df))
df[random, ]
}
shuffle_df(deck)
## Book solution
shuffle <- function(cards) {
random <- sample(1:52, size = 52)
cards[random, ]
}
deal(deck)
deck2 <- shuffle(deck)
deal(deck2)
```
### Dollar Signs and Double Brackets
```{r}
deck$value
mean(deck$value)
median(deck$value)
lst <- list(numbers = c(1, 2), logical = TRUE, strings = c("a", "b", "c"))
lst
lst[1]
sum(lst[1])
lst$numbers
sum(lst$numbers)
lst[[1]] # does the same that $
lst["numbers"]
lst[["numbers"]]
```
## Chapter 5. Modifying Values
```{r}
deck2 <- deck
```
### Changin Values in Place
```{r}
vec <- c(0, 0, 0, 0, 0, 0)
vec
vec[1]
vec[1] <- 1000 # Changing first value within the vector
vec
vec[c(1, 3, 5)] <- c(1, 1, 1)
vec
vec[4:6] <- vec[4:6] + 1
vec
vec[7] <- 0
vec
deck2$new <- 1:52
head(deck2)
deck2$new <- NULL
head(deck2)
deck2[c(13, 26, 39, 52), ]
deck2[c(13, 26, 39, 52), 3]
deck2$value[c(13, 26, 39, 52)]
deck2$value[c(13, 26, 39, 52)] <- c(14, 14, 14, 14)
# or
deck2$value[c(13, 26, 39, 52)] <- 14
head(deck2, 13)
deck3 <- shuffle(deck)
head(deck3)
```
### Logical Subsetting
```{r}
vec
vec[c(FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE)]
```
#### Logical Tests
```{r}
1 > 2
1 > c(0, 1, 2)
c(1, 2, 3) == c(3, 2, 1)
1 %in% c(3, 4, 5)
c(1, 2) %in% c(3, 4, 5)
c(1, 2, 3) %in% c(3, 4, 5) ##
c(1, 2, 3, 4) %in% c(3, 4, 5) ##
```
##### Exercise 5.1 (p. 82)
Extract the `face` column of `deck2` and test whether each value is equal to `ace`. As a challenge, use R to quickly count how many cards are equal to `ace`.
```{r}
deck2$face
deck2$face == 'ace'
sum(deck2$face == 'ace')
```
```{r}
deck3$face == "ace"
deck3$value[deck3$face == "ace"]
deck3$value[deck3$face == "ace"] <- 14
head(deck3)
```
##### Exercise 5.2 (p. 84)
```{r}
deck4 <- deck
deck4$value <- 0
head(deck4, 13)
```
Assign a value of 1 to every card in deck4 that has a suit of hearts.
```{r}
deck4$suit
deck4$suit == "hearts"
deck4$value[deck4$suit == "hearts"] <- 1
deck4[deck4$suit == "hearts", ]
```
```{r}
deck4[deck4$face == "queen", ]
deck4[deck4$suit == "spades", ]
```
#### Boolean Operators
```{r}
a <- c(1, 2, 3)
b <- c(1, 2, 3)
c <- c(1, 2, 4)
a == b
b == c
a == b & b == c
deck4$face == "queen" & deck4$suit == "spades"
queenOfSpades <- deck4$face == "queen" & deck4$suit == "spades"
deck4[queenOfSpades, ]
deck4$value[queenOfSpades]
deck4$value[queenOfSpades] <- 13
deck4[queenOfSpades, ]
```
##### Exercise 5.3 (p. 87)
If you think you have the hang of logical tests, try converting these sentences into tests written with R code. To help you out, I’ve defined some R objects after the sentences that you can use these to test your answers:
• Is w positive?
• Is x greater than 10 and less than 20?
• Is object y the word February?
• Is every value in z a day of the week?
```{r}
w <- c(-1, 0, 1)
x <- c(5, 15)
y <- "February"
z <- c("Monday", "Tuesday", "Friday")
```
```{r}
w > 0
x > 10 & x < 20
y == "February"
weekdays <- c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); z %in% weekdays
# or
all(z %in% c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday", "Sunday"))
```
***
blackjack
```{r}
deck5 <- deck
head(deck5, 13)
facecard <- deck5$face %in% c("king", "queen", "jack")
deck5[facecard, ]
deck5$value[facecard] <- 10
head(deck5, 13)
```
***
### Missing Information
```{r}
1 + NA
NA == 1
```
#### na.rm
```{r}
c(NA, 1:50)
mean(c(NA, 1:50))
mean(c(NA, 1:50), na.rm = TRUE)
```
#### is.na
```{r}
NA == NA
c(1, 2, 3, NA) == NA
is.na(NA)
vec <- c(1, 2, 3, NA)
is.na(vec)
```
```{r}
deck5$value[deck5$face == "ace"] <- NA
head(deck5, 13)
```
## Chapter 6. Environments
```{r}
deal(deck)
deal(deck)
deal(deck)
```
### Environments
```{r}
library(pryr)
pryr::parenvs(all = TRUE)
```
### Working with Environments
```{r}
as.environment("package:stats")
globalenv()
baseenv()
emptyenv()
parent.env(globalenv())
parent.env(emptyenv())
ls(emptyenv())
ls(globalenv())
ls.str(globalenv())
head(globalenv()$deck, 3)
assign("new", "Hello Global", envir = globalenv())
globalenv()$new
```
#### The Active Environment
```{r}
environment()
```