-
Notifications
You must be signed in to change notification settings - Fork 1
/
chapter1.Rmd
816 lines (537 loc) · 24.1 KB
/
chapter1.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
---
title : Hello R
description : Basics of R, the amazing statistical programming language. Do not be afraid of the art of programming!
--- type:PureMultipleChoiceExercise lang:r xp:50 skills:1 key:a253f2e756
## What is R?
Welcome to part 1 of **R Short and Sweet**: Hello R.
R is a programming language designed for statistical analysis. R is completely open source and all analysis done with R are reproduciple and easy to share. R is flexible, powerful and includes implementations of the latest research.
Because of these reasons, R is a very popular language among the scientific community. R is however also widely [used](http://blog.revolutionanalytics.com/2014/05/companies-using-r-in-2014.html) for data analysis and visualisations by companies such as Google, Facebook, Twitter and Reaktor. R is perfect for data science.
Researchers and experts use R to visualize and explore data and implement new statistical methods. The purpose of this short course is to expose you to the basics of programming and data analysis with R.
Choose the correct answer.
*** =possible_answers
- R is a programming language for statistical computing
- R is open source
- R is widely used for data science
- [All of the above]
*** =feedbacks
- This is true, but not the correct answer
- This is true, but not the correct answer
- This is true, but not the correct answer
- Correct!
--- type:NormalExercise lang:r xp:50 skills:1 key:59231c671b
## Running R code
R code can be written with a simple text editor. R code is just written instructions which the computer can understand. When you want the computer to make an action based on your R code, you must *run* the code (also called *executing*).
Follow the instructions below to complete the exercise.
*** =instructions
- On the right side, the script.R is a text editor which contains R code. When the code is *run*, it gives your computer the instructions to (1) load a dataset and (2) produce a graphic.
- Click on 'Run code' to run the code.
- Click 'Submit Answer' to move on to the next exercise!
***= hint
- Simply press 'Submit Answer' when you're ready to move forward.
*** =pre_exercise_code
```{r}
# load data
learning2014 <- read.table("http://www.helsinki.fi/~kvehkala/JYTmooc/learning2014.txt", sep = "\t", header = TRUE)
# Access the ggplot2 package
library(ggplot2)
```
*** =sample_code
```{r}
# This is a text editor which contains R code
# load data
learning2014 <- read.table("http://www.helsinki.fi/~kvehkala/JYTmooc/learning2014.txt", sep = "\t", header = TRUE)
# Access the 'ggplot2' graphics package
library(ggplot2)
# A scatter plot of students attitude and exam points
qplot(attitude, points, col = gender, data = learning2014) + geom_smooth(method = "lm")
```
*** =solution
```{r}
# This is a text editor which contains R code
# load data
learning2014 <- read.table("http://www.helsinki.fi/~kvehkala/JYTmooc/learning2014.txt", sep = "\t", header = TRUE)
# Access the 'ggplot2' graphics package
library(ggplot2)
# A scatter plot of students attitude and exam points
qplot(attitude, points, col = gender, data = learning2014) + geom_smooth(method = "lm")
```
*** =sct
```{r}
success_msg("Great! Move on to the next exercise.")
```
--- type:NormalExercise lang:r xp:100 skills:1 key:cdaeb146ec
## Basic tools
On your right you see the R editor area - the script.R - and below that the R console. The editor area is just a simple text editor where you write code - just like text.
You can first write code to the editor area and then tell R that you want to execute a line of code where your cursor currently is by pressing `Ctrl + Enter` (`Cmd + Enter` on a mac). Input and output will then appear in the console.
It is also possible to write code directly to the console and use `Enter` to execute, but working with the script area is preferred.
Try it!
*** =instructions
- Type "Hello world!" in the editor area. Use quotation marks.
- Press `Ctrl + Enter` to execute your "Hello world!" - code
- Make sure to use a capital "H" and an exclamation mark.
- Click 'Submit Answer' when done.
*** =hint
- Remember to use quotation marks and write the sentence exactly as instructed.
*** =pre_exercise_code
```{r}
# no pec
```
*** =sample_code
```{r}
# This is the R editor!
# A hashtag at the beginning of the line defines the line as a comment
# Write your code below
# Below is the R console, where you will see output
```
*** =solution
```{r}
# This is the R editor!
# A hashtag at the beginning of the line defines the line as a comment
# write your code below
"Hello world!"
# Below is the R console, where you will see output
```
*** =sct
```{r}
test_student_typed("Hello world!", not_typed_msg="Please type 'Hello world!' in the editor.")
test_error()
success_msg("Great work! You have now executed your first line of code :)")
```
--- type:NormalExercise lang:r xp:100 skills:1 key:a6d98b0c0b
## Arithmetics
Let's continue with something simple. R can do amazing things like scrape websites and draw beautiful graphics but it can also do basic calculations. Consider the following arithmetic operators:
- Addition: `+`
- Subtraction: `-`
- Multiplication: `*`
- Division: `/`
- Exponentiation: `^` (or `**`)
The `^` operator raises the number to its left to the power of the number to its right: for example `3^2` is 9. With this knowledge, follow the instructions below to complete the exercise.
*** =instructions
- Study and execute the examples in the R script. (Use `Ctrl + Enter` or `Cmd + Enter`)
- Type `2^5` in the editor and calculate 2 to the power 5.
- When done, click 'Submit Answer'.
*** =hint
- If you have trouble accessing the `^` -sign, you can also use double star `**`.
*** =pre_exercise_code
```{r}
# no pec
```
*** =sample_code
```{r}
# An addition
5 + 5
# A subtraction
5 - 5
# A multiplication
3 * 5
# A division
(5 + 5) / 2
# Exponentiation
```
*** =solution
```{r}
# An addition
5 + 5
# A subtraction
5 - 5
# A multiplication
3 * 5
# A division
(5 + 5) / 2
# Exponentiation
2 ^ 5
```
*** =sct
```{r}
test_output_contains("2^5", incorrect_msg = "The exponentiation example is not correct. Please write `2 ^ 5` on a new line.")
success_msg("Great work! Head over to the next exercise.")
```
--- type:NormalExercise lang:r xp:100 skills:1 key:aac1b8c5d1
## Objects
Here's where things start to get interesting. In R you can create and operate on things called *objects*.
An object is something that can store information such as multiple numerical values and names. Once an object is created, it will be stored in memory and the information it contains will be available to you later.
Objects are created using the assign operator: `<-` (< and -). The contents of an object can be printed by typing it's name.
*** =instructions
- Execute the lines that create and operate on `my_character_object` and `my_numeric_object`.
- Assign your name or nickname to `my_name`. Use quotation marks.
- Assign a positive message to yourself to `my_message`. Use quotation marks.
- Click 'Submit Answer'.
*** =hint
- Remember that `Ctrl + Enter` executes a single row.
*** =pre_exercise_code
```{r}
# no pec
```
*** =sample_code
```{r}
# Create an object
my_character_object <- "Hi there!"
# Print the contents of the object
my_character_object
# Create another object
my_numeric_object <- 5 + 5
# Do further calculations with the object
my_numeric_object / 5
# Override the value of an object by assigning a new value to it
my_character_object <- my_numeric_object
my_character_object
# Create character objects my_name and my_message here. Use quotation marks.
my_name <-
my_message <-
```
*** =solution
```{r}
# Create an object
my_character_object <- "Hi there!"
# Print the contents of the object
my_character_object
# Create another object
my_numeric_object <- 5 + 5
# Do further calculations with the object
my_numeric_object / 5
# Override the value of an object by assigning a new value to it
my_character_object <- my_numeric_object
my_character_object
# Create character objects my_name and my_message here. Use quotation marks.
my_name <- "Hey You"
my_message <- "You are awsome!"
```
*** =sct
```{r}
test_object("my_name", eval = F, incorrect_msg = "Did you assign your name to `my_name`?")
test_object("my_message", eval = F, incorrect_msg = "Did you assign a message to `my_message`?")
test_error(incorrect_msg = "Did you use quotation marks to assign your name and a message to the objects `my_name` and `my_message`")
success_msg(paste0("Great job ", my_name, ". ", my_message, "!"))
```
--- type:NormalExercise lang:r xp:100 skills:1 key:dc84cbe247
## Functions
In R you operate on objects using *functions*. A function is a special kind of object that uses other objects as inputs, performs operations, and usually outputs a result. The inputs of a function are called *arguments*.
A Function is *called* by typing it's name and giving it the necessary arguments inside parenthesis. When a function is called, it will perform an action.
R has many functions ready for you to use. Functions are how you're actually going to do all the magic. Here we will do a little bit of magic using data that will become more familiar to you later on.
*** =instructions
- Create object `student_height` and compute the mean height of students. Don't worry about the `$` -sign for now, we will get to that later.
- Create object `student_age` and compute the mean age of students
- When done, click 'Submit Answer'
*** =hint
- Use the function `mean()` and the object `student_age` like in the example on line 7 of script.R.
*** =pre_exercise_code
```{r}
students2014 <- read.table("http://www.helsinki.fi/~kvehkala/JYTmooc/JYTOPKYS-data.txt", sep="\t", header=TRUE)
# keep a couple background variables
students2014 <- students2014[,c("sukup","toita","ika","pituus","kenka","kone")]
# recode kone -variable NA values as factor levels
students2014$kone <- addNA(students2014$kone)
# choose rows without missing values
students2014 <- students2014[complete.cases(students2014),]
# integers to numeric
students2014$ika <- as.numeric(students2014$ika)
students2014$pituus <- as.numeric(students2014$pituus)
students2014$kenka <- as.numeric(students2014$kenka)
```
*** =sample_code
```{r}
# students2014 data is available
# Create object student_height
student_height <- students2014$pituus
# Compute the average height of the students
mean(student_height)
# Create object student_age
student_age <- students2014$ika
# Compute the average age of the students
```
*** =solution
```{r}
# students2014 data is available
# Create object student_height
student_height <- students2014$pituus
# Compute the average height of the students
mean(student_height)
# Create object student_age
student_age <- students2014$ika
# Compute the average age of the students
mean(student_age)
```
*** =sct
```{r}
test_output_contains("mean(student_age)", incorrect_msg = "Please use the `mean()` function to compute the mean of student_age.")
test_error()
success_msg("Excellent! You are making great progress.")
```
--- type:NormalExercise lang:r xp:100 skills:1 key:dc76ff838a
## Good arguments
During this course you will operate on R's ready-made functions. As you already saw, functions take objects as their arguments and then perform actions using the objects. Using a function is called *calling* it.
Functions usually have more than one possible argument. Some of the arguments can have default values and others need to be specified. The arguments have names, which can (and often should) be used when specifying their values. The recommended style is to specify all but the first argument by name, when calling a function.
Multiple arguments are separated with a comma.
*** =instructions
- Study and execute the example codes where the function `head()` is used to explore the first couple observations of the `students2014` dataset.
- Using the assign operator `<-`, create object `first_ten_students` by calling `head()` with `n = 10`.
*** =hint
- Directly assign the output of `head()` to `first_ten_students` to create the object
- The answer is of the form: `first_ten_students <- head(arguments_here)`
- Remember to separate function arguments with a comma
*** =pre_exercise_code
```{r}
# load data from web
students2014 <- read.table("http://www.helsinki.fi/~kvehkala/JYTmooc/JYTOPKYS-data.txt", sep="\t", header=TRUE)
# keep a couple background variables
students2014 <- students2014[,c("sukup","toita","ika","pituus","kenka","kone")]
# recode kone variables missing values as factor levels
students2014$kone <- addNA(students2014$kone)
# keep only rows without missing values
students2014 <- students2014[complete.cases(students2014),]
# integers to numeric
students2014$ika <- as.numeric(students2014$ika)
students2014$pituus <- as.numeric(students2014$pituus)
students2014$kenka <- as.numeric(students2014$kenka)
```
*** =sample_code
```{r}
# students2014 is available
# Use the function head() on the object students2014
head(students2014, n = 4)
# Argument 'n' of head() has a default value 6
head(students2014)
# These calls are identical. Try them.
head(students2014, n = 3) # recommended style
head(students2014, 3) # style usually not recommended
head(n = 3, students2014) # style not recommended
# Save the first ten observations of the data to an object
first_ten_students <-
```
*** =solution
```{r}
# students2014 is available
# Use the function head() on the object students2014
head(students2014, n = 4)
# Argument 'n' of head() has a default value 6
head(students2014)
# These calls are identical. Try them.
head(students2014, n = 3) # recommended style
head(students2014, 3) # style usually not recommended
head(n = 3, students2014) # style not recommended
# Save the first ten observations of the data to an object
first_ten_students <- head(students2014, n = 10)
```
*** =sct
```{r}
test_error(incorrect_msg = "Your code seems to produce an error. Did you create the object `first_ten_students` as instructed?")
test_object("first_ten_students")
success_msg("Great job!")
```
--- type:NormalExercise lang:r xp:100 skills:1 key:a8d5dff737
## Data frames
In R, the basic idea is to use *functions* to operate on objects. The most common object to operate on is the `data frame` object, which stores data in tabular form.
The columns in data frames are vectors. Data frames can contain multiple vectors with different data types. You will soon learn more about vectors and data types.
Here you will get to apply some functions that are helpful for inspecting data: `head()` and `str()`. You will also learn how to access the columns of a data frame using the $-sign.
*** =instructions
- Execute the function `head()` and see the results
- Inspect the data types in the `students2014` data with the function `str()`
- Note that `students2014$ika` prints out all the ages of the students in `students2014`
- Use the $-sign to access the students shoe size (column `kenka`) in `students2014` data
*** =hint
- The data is stored in object `students2014`
*** =pre_exercise_code
```{r}
students2014 <- read.table("http://www.helsinki.fi/~kvehkala/JYTmooc/JYTOPKYS-data.txt", sep="\t", header=TRUE)
# keep a couple background variables
students2014 <- students2014[,c("sukup","toita","ika","pituus","kenka","kone")]
# recode kone -variable NA values as factor levels
students2014$kone <- addNA(students2014$kone)
# choose rows without missing values
students2014 <- students2014[complete.cases(students2014),]
# integers to numeric
students2014$ika <- as.numeric(students2014$ika)
students2014$pituus <- as.numeric(students2014$pituus)
students2014$kenka <- as.numeric(students2014$kenka)
```
*** =sample_code
```{r}
# students2014 is available
# Let's view the first 6 students from the students2014 data
head(students2014)
# View the structure of students2014
str(students2014)
# You can access the variables in the students2014 data by using the $-sign
students2014$ika
# Access the shoe sizes of the students
```
*** =solution
```{r}
# students2014 is available
# Let's view the first 6 students from the students2014 data
head(students2014)
# View the structure of students2014
str(students2014)
# You can access the variables in the students2014 data by using the $-sign
students2014$ika
# Access the shoe sizes of the students
students2014$kenka
```
*** =sct
```{r}
test_output_contains("students2014$kenka", incorrect_msg = "Did you use the $-sign to access the shoe size variable?")
# test if the students code produces an error
test_error()
# Final message the student will see upon completing the exercise
success_msg("Well done! You are really getting the hang of it.")
```
--- type:NormalExercise lang:r xp:100 skills:1 key:792094dea8
## Data types (1)
In these next exercises you wil learn about the data types in R. You will also get familiar with vectors and their usage. What do data types and vectors have to do with each other? A lot, you'll see!
There are different data types in R. The most commonly used are:
- Numbers and decimal values are called **numeric**
- Text or character values are called **characters**
- [Boolean values](https://en.wikipedia.org/wiki/Boolean_data_type) (`TRUE` or `FALSE`) are called **logical**
When creating character values, one needs to use quotation marks (both `' '` and `" "` will work). For example `"Statistics<3"` would be a character value in R. Numeric and boolean values do not need quotation marks. Boolean values `TRUE` and `FALSE` can be abbreviated with `T` and `F`.
You can use the function `str()` (str is short for structure) to find out what data type the object is.
*** =instructions
- Create character object `my_character` by assigning your initials in it.
- Assign the number 10.5 to `my_numeric`. Note that the decimal separator in R is dot instead of comma.
- Create the object `my_logical` by executing the line. Note that with boolean values, no quotation marks are needed.
- Change the value of `my_logical` to `TRUE`
- Inspect the data types of the objects with `str()`.
*** =hint
- When creating a character object, remember to use quotation marks.
- Dot is the decimal mark in R: `2.5` is decimal number but `2,5` means a different thing!
- Remember that `Ctrl + Enter` executes a single row.
- You can use `str()` by putting the object name inside the parenthesis.
*** =pre_exercise_code
```{r}
```
*** =sample_code
```{r}
# Create three objects with different data types
my_character <-
my_numeric <-
my_logical <- FALSE
# See how each object looks with the function str()
```
*** =solution
```{r}
# Create three objects with different data types
my_character <- "A.B.C."
my_numeric <- 10.5
my_logical <- TRUE
# See how each object looks with the function str()
str(my_character)
str(my_numeric)
str(my_logical)
```
*** =sct
```{r}
test_object("my_character", eval=FALSE, incorrect_msg = "Did you assign your initials to `my_character`?")
test_object("my_numeric", incorrect_msg="Did you assign the correct value to `my_numeric`?")
test_object("my_logical", incorrect_msg="Did you change the value of `my_logical`?")
test_output_contains("str(my_character)", incorrect_msg = "Did you use `str()` on `my_character`?")
test_output_contains("str(my_numeric)", incorrect_msg = "Did you use `str()` on `my_numeric`?")
test_output_contains("str(my_logical)", incorrect_msg = "Did you use `str()` on `my_logical`?")
# test if the students code produces an error
test_error()
# Final message the student will see upon completing the exercise
success_msg("You're making great progress, well done!")
```
--- type:NormalExercise lang:r xp:100 skills:1 key:02be1c797a
## Data types (2)
Another one of R's data types is called factor. Factors contain numbers, but for every number there is a character value associated to it. A variable measured by the [Likert scale](https://en.wikipedia.org/wiki/Likert_scale) could for example be coded as a factor: the values are numbers from 1 to 5, but the numbers also have words attached to them such as:
- "Strongly disagree" = 1
- "Strongly agree" = 5
In R it is also possible to create factors from numerical objects by using the function `cut()`, which splits a variable into categories. It has a mandatory argument `breaks`, which defines the cutting points of the categories.
*** =instructions
- Create objects `student_age` and `student_age_cut`
- Use `str()` to inspect `student_age_cut`
- Use `head()` to print the first six values of `student_age`
- Use `head()` to print the first six values of `student_age_cut`
*** =hint
- Give the object `student_age_cut` as the first argument to `str()` and `head()`.
*** =pre_exercise_code
```{r}
students2014 <- read.table("http://www.helsinki.fi/~kvehkala/JYTmooc/JYTOPKYS-data.txt", sep="\t", header=TRUE)
# keep a couple background variables
students2014 <- students2014[,c("sukup","toita","ika","pituus","kenka","kone")]
# recode kone -variable NA values as factor levels
students2014$kone <- addNA(students2014$kone)
# choose rows without missing values
students2014 <- students2014[complete.cases(students2014),]
# integers to numeric
students2014$ika <- as.numeric(students2014$ika)
students2014$pituus <- as.numeric(students2014$pituus)
students2014$kenka <- as.numeric(students2014$kenka)
```
*** =sample_code
```{r}
# students2014 is available
# Let's access the (numerical) age vector of the students2014 and save it to another object.
student_age <- students2014$ika
# Let's use the cut()-function to cut the variable in categories
student_age_cut <- cut(student_age, breaks = c(15, 25, 35, 100))
# Inspect the data type of student_age_cut
# Print the first 6 elements of student_age and student_age_cut
```
*** =solution
```{r}
# students2014 is available
# Let's access the (numerical) age vector of the students2014 and save it to another object.
student_age <- students2014$ika
# Let's use the cut()-function to cut the variable in categories
student_age_cut <- cut(student_age, breaks = c(15, 25, 35, 100))
# Inspect the data type of student_age_cut
str(student_age_cut)
# Print the first 6 elements of student_age and student_age_cut
head(student_age)
head(student_age_cut)
```
*** =sct
```{r}
test_function("str", args="object", incorrect_msg = "Did you use the `str()` to look at the object 'student_age_cut'?")
test_output_contains("head(student_age)", incorrect_msg = "Did you use `head()` and look at the first six elements of `student_age`?")
test_output_contains("head(student_age_cut)", incorrect_msg = "Did you use `head()` to look at the first six elements of `student_age_cut`?")
# test if the students code produces an error
test_error()
# Final message the student will see upon completing the exercise
success_msg("Good work!")
```
--- type:NormalExercise lang:r xp:100 skills:1 key:dc3cc379e2
## Vectors
A vector is an object containing multiple elements of the same data type. Vectors are quite important in R. The columns of a data frame (such as `student2014`) are vectors.
You can create your own vectors by combining values of the same data type, using the function `c()`.
*** =instructions
- See and execute the examples on how to create a vector with `c()`.
- Create a character vector `character_vector`.
- Create a vector `logical_vector` with boolean values `TRUE, FALSE, TRUE, FALSE`.
- Print the contents of `logical_vector`.
*** =hint
- When creating boolean values, no quotation marks are needed.
- You can print the contents of an object by typing it's name.
*** =pre_exercise_code
```{r}
```
*** =sample_code
```{r}
# Here we create a vector with numeric elements
c(2, 3, 4, 5)
# Another one
c(0.1, 0.2, 5.84, 0.7)
# Let's create one with characters and save it to a object
character_vector <- c("a", "b", "c", "d")
# Create a logical vector and print it
```
*** =solution
```{r}
# Here we create a vector with numeric elements
c(2, 3, 4, 5)
# Another one
c(0.1, 0.2, 5.84, 0.7)
# Let's create one with characters and save it to a object
character_vector <- c("a", "b", "c", "d")
# Create a logical vector and print it
logical_vector <- c(TRUE, FALSE, TRUE, FALSE)
logical_vector
```
*** =sct
```{r}
test_object("logical_vector", incorrect_msg = "Did you create `logical_vector` with same values as instructed?")
test_output_contains("logical_vector", incorrect_msg = "Did you print the contents of `logical_vector`?")
test_error()
# Final message the student will see upon completing the exercise
success_msg("Great work!")
```