-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignment-0.Rmd
156 lines (91 loc) · 2.68 KB
/
assignment-0.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
---
title: "Assignment 0 - Getting started"
author: "FILL IN YOUR FULL NAME + GITHUB USERNAME"
date: "`r format(Sys.time(), '%B %d, %Y | %H:%M:%S | %Z')`"
output:
html_document:
code_folding: show
df_print: paged
highlight: tango
number_sections: no
theme: cosmo
toc: no
---
<style>
div.answer {background-color:#f3f0ff; border-radius: 5px; padding: 20px;}
</style>
```{r, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
eval = TRUE,
error = FALSE,
message = FALSE,
warning = FALSE,
comment = NA)
```
<!-- Do not forget to input your Github username in the YAML configuration up there -->
***
```{r, include = T}
# LOAD THE PACKAGES YOU ARE USING IN THIS CODE CHUNK library(nameofpackage)
```
### Task 1 - Dealing with a numeric vector
Consider the following numeric vector.
```{r}
x <- c(34, 56, 55, 87, NA, 4, 77, NA, 21, NA, 39)
```
a) What's the mean of all values? And what's the median?
```{r}
```
b) What's the variance and the standard deviation of all values?
```{r}
```
c) Compute the sum of all values in the vector `x`.
```{r}
```
d) Create a new vector, `x_std`, that standardizes `x`, i.e. transforms the values in a way that `mean(x_std) = 0` and `sd(x_std) = 1`.
```{r}
```
<br>
***
### Task 2 - Dealing with a character vector
Consider the following character vector.
```{r}
friends <- c("Homer", "Marge", "Bart", "Lisa", "Maggie")
```
a) Get the length of the vector.
```{r}
```
b) Extract the first two elements of the vector.
```{r}
```
c) Extract the second and the last observation from the vector.
```{r}
```
d) Sort the elements in reverse alphabetic order.
```{r}
```
<br>
***
### Task 3 - A dataset on immigration trips to Ellis Island
a) Load the dataset `immigration-ellis.tsv` into R, which contains data on immigration to Ellis Island (1918-1922) by trip.
```{r}
```
b) What is the total number of immigration cases in the dataset?
```{r}
```
c) From where did the ship with the most immigrants arrive?
```{r}
```
d) How many unique ships (according to the name) are in the dataset?
```{r}
```
e) Find out the name of the package from the tidyverse that makes working with date and times data easier, and report it below!
<!-- During this course, we will input our answers that include text inside the tag, as such:
<div class = "answer">
YOU PUT YOUR TEXT HERE
</div>
Also, you will notice that the text you put inside here will not appear in your .html file.
That is because very similar to the # in our R scripts, this is a comment tag for html.
-->
<div class = "answer">
YOUR TEXT SHOULD GO HERE
</div>