-
Notifications
You must be signed in to change notification settings - Fork 1
/
01_mini_exercises.Rmd
47 lines (36 loc) · 1.79 KB
/
01_mini_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
---
title: "summeRworkshop mini exercises"
author: "Gregor Pirs, Jure Demsar and Erik Strumbelj"
date: "25/7/2019"
output:
prettydoc::html_pretty:
theme: architect
toc: no
highlight: github
---
<div style="text-align:center">
<img src="./bstatcomp.png" alt="drawing" width="128"/>
</div>
## Mini exercises -- R introduction and dplyr
### Vectors
Let $m = 9$.
* Create a vector $x$, which is a sequence of equally spaced numbers
between -2 and 2 of length $m$.
* Create a vector $y$ of the squares of first $m$ integers.
* Create a vector $z$ by dividing $y$ by $x$.
* Find the mean of $z$.
* Create a data frame with x, y and z.
### Data frame
Open the _01_data_frame_exercise.R_ script and run it. Now you should have a data frame in your working environment. Do the following (using base R and dplyr for comparison):
* Summarize the data frame.
* Print only females.
* Print all males taller than 180cm.
* Create a new variable which shows the BMI of each person.
* (only dplyr) Print average ages across genders.
* (only tidyr) Transform the data frame into a long format, where height, weight and age are the measurements.
### Functions
Write a function that takes vectors $x$ and $y$ of the same length and a
real value $z$. The function should return the number of indices $i$, where
$x_i + y_i > z$.
### Debugging
Open the _01_debug_\__exercise.R_ script. The script contains a small program, which should return all prime numbers up to the parameter. It does so by first looping through all the integers (greater than 2) and second looping through smaller integers than the current one to check if any of them divide it. Run the script. Apparently the function does not work as it should. Debug it with `browser()` by checking the values of variables at each iteration and correct the mistake.