Homework 1
Due 29 September 24:00.
Send the hw1_<your-last-name>.R
file to divenyi_janos@phd.ceu.edu.
Task 0
Finish practice examples 1. For yourself. (They won’t be graded.)
Task 1
Write a function which defines whether a number is prime. You can presume that
your function will take an integer as argument. (Hint: the %%
operator gives
the remainder after division. So 5 %% 3 = 2
and 5 %% 5 = 0
.)
Task 2
Write a function which takes a non-negative numeric vector and returns back a
0-1 vector according to the followings: zero elements should stay zero and
positive elements should be transformed to one. Call this function as dummify
.
For example, if a <- c(0, 34, 2)
then the dummify(a)
should return c(0, 1,
1)
. (You can assume that the function will only get vectors with non-negative elements.)
Task 3
In Data directory you find a trade.zip
folder. Download and extract it to
a directory in your machine. You are going to find 11 csv
files there which
contain trade data from World Bank from different years. Load and bind them
together following the steps below:
- Load the file.
- Create a year variable which takes the value of that year.
- Bind this file to the rest.
Hint: You can achive this with a for loop by looping over the years.