Part 1

We are going to creat a small dataset with data from four different participants, relating to their response to some form of treatment. 

Exercise 1

Create a variable containing the numbers 1-4 in ascending order, using the function. Call the variable ID.

Exercise 2

Create a variable containing the numbers 2,2,1,1 in that order, using the function. Call the variable group.

Exercise 3

Create a variable called response, where possible categories are poor, medium and good. You can decide how each person responds as you want, but remember that this variable should be changed into an ordered factor.

Exercise 4

Combine all variables into a data frame. You can call the dataset patientData.

Exercise 5

Print case no. 2, then variable 3, and finally the value of variable 3 only for case no. 2.

Exercise 6

Print all cases except case no 1.

Part 2

Exercise 1

Based on the information you can get from str(data$variable) and summary(data$variable), can you find out which years you have data from?

 

Exercise 2

What happens if you combine the summary function with as.factor(date$variable) for the variable year? Does this change the variable itself?

Part 3

Exercise 1

Create a new variable called gdpPercap1000, which corresponds to the GDP per capita in 1000 USD instead of USD.

Exercise 2

Calculate the average population for 2007 group by the life expectancy categories in lifeCat, and count the number of countries you have in each of the categories (hint: n()).

 

Part 4

Exercise 1

Create a proportional table showing categorical life expectancy (LifeCat) vs continent, with percentages instead of decimal numbers.