Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
12 views

Assignment_1-2

Uploaded by

e.stephenson
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Assignment_1-2

Uploaded by

e.stephenson
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment 1

Instructions (please read carefully)

General information: This assignment focuses on building up your knowledge and


familiarity with R and RStudio as well as the logic of object-oriented statistical languages.

Submitting the assignment: Please use this word file as your starting point. Add your
answers in the boxes below the questions. Please also copy-paste the R code that you use if
the question asks you to do so. Once you have completed it, convert this word document to
pdf and submit the pdf as well as the R script that you used to come to the answers in Canvas
-> Assignments -> Assignment 1.

Remember to upload the files to Canvas on Thursday before 12h.

Please name the pdf document and the R script: “A1RIB_TeamName”. For example, if Team
A submitted the files, they would be named A1RIB_TA.pdf & A1RIB_TA.R. Each team
should submit only one file.

To check:

1. Make sure that you create a main folder for this assignment (you can name the folder
something like “A1_RIB” or whatever you like).
2. This folder can consist of sub-folders like code, data…
3. Set the working directory as your main folder (under Session -> Set Working
Directory).
4. Consult the R instructional videos and the “A very short introduction to R document
by Torfs & Brauer” to help you get started.

Questions

Basics

1. Install and load the package “tidyverse”. Please copy in the code you used.
a. Report at least one other way of installing a package.

( 73+4 )∗15
2. Compute and assign the name calculation to the result. Print calculation
√ 43
to the console and report the value below. Please copy in the code you used.
a. Now, standardize calculation by subtracting its mean and dividing by its
standard deviation. What is the result and why? Please copy in the code you
used.
3. Create a vector called “a” that has the numbers 1 to 50. Then create a vector called
“b” that has the numbers 51 to 100. Assign the two vectors to a matrix called m1 that
has 2 columns. Please copy in the code you used.

4. Create a vector called months containing the numbers 76, 32, 84, and 9. Compute a
vector called years from it by dividing months by 12. Report the value of years below
and copy in the code you used.

Comparisons and logical operators

R, like many other languages uses (logical) operators to perform comparison tests.
Understanding how these operators work is essential to writing code. The operators are:
- > greater
- > = greater or equal
- < less
- < = less or equal
- = = equals
- ! = does not equal
- & AND
- | OR
- There are also if(), else if(), ifelse(), else but let's not get carried away for now.

5. What happens when you check whether a is larger than b? Explain. Note that you
created these vectors above.

6. Is the mean of a smaller or equal to the mean of b. Please copy in the code you used.
How is this operation different than in question 5?

7. Is the vector c(1, “a”, 3) equal to the vector c(1, 2, “3”)? Do you think it makes sense
what R is doing here?
8. Imagine there is a medical study and patients should be excluded from the study if
they weigh more than 90 kg or if they are younger than 18 years. Define the vector
age as age <- c(50,17,21,16,90) and the vector weight as weight <-
c(80,75,92,106,69). Then write a logical statement involving these two variables
that tests for the exclusion criteria. How many people qualify for the study? Please
copy in the code you used.

Graphics and data

9. Load the d1.csv dataset into R and object called data1. Which function do you need to
use and why? Report at least one other way on how you could load this data. Please
copy in the code you used.

10. Create a vector called new that is the result of a product of the variables "ahi01" and
"ahi02" from the data1 dataset. Why is this vector not another variable in the data1
dataset? Please copy in the code you used.

11. Create a histogram of the elapsed.days variable from the data1 dataset. What type of
distribution is this?

12. Create a scatter plot between the variables ahiTotal and cesdTotalfrom the data1
dataset. Can you already comment on the direction of the relationship between these
two variables? Hint: you can use plot() or a more complex version from the ggplot2
package.
a. For a bonus, try to give the plot a title and change the x and y coordinate
names.
Where are the mistakes:

13. If you run the following code: L1 <- list(a,b,data2) what type of error will you get
and why? How would you solve it?

14. If you run the following code: c <- c(a, b, 5, 6,7 8, 9) where is the mistake? How
would you solve it?

15. Why will the value of d <- a[51] be NA?

You might also like