Publications by r-exercises
Matrix exercises
Please note, solutions are available here. Exercise 1 Create three vectors x,y,z with integers and each vector has 3 elements. Combine the three vectors to become a 3×3 matrix A where each column represents a vector. Change the row names to a,b,c. Think: How about each row represents a vector, can you modify your code to implement it? ...
3004 sym 2 img
Array exercises
Exercise 1 Create an array (3 dimensional) of 24 elements using the dim() function. Exercise 2 Create an array (3 dimensional) of 24 elements using the array() function. Exercise 3 Assign some dimnames of your choice to the array using the dimnames() function. Exercise 4 Assign some dimnames of your choice to the array using the argum...
1716 sym 2 img
Missing values
Today we’re training how to handle missing values in a data set. Before starting the exercises, please first read section 2.5 of An Introduction to R. Solutions are available here. Exercise 1 If X <- c (22,3,7,NA,NA,67) what will be the output for the R statement length(X) Exercise 2 If X = c(NA,3,14,NA,33,17,NA,41) write some R code...
2455 sym 2 img
Character vector exercises
In the exercises below we cover the basics of character vectors. Before proceeding, first read section 2.6 of An Introduction to R, and the help pages for the nchar, substr and sub functions. Answers to the exercises are available here. Exercise 1 If x <- “Good Morning! “, find out the number of characters in X a. 1 b. 14 c. 13 Exercise 2 Con...
2194 sym 2 img
Index vectors
In the exercises below we cover the basics of index vectors. Before proceeding, first read section 2.7 of An Introduction to R, and the help pages for the sum, and which functions. Answers to the exercises are available here. Exercise 1 If x <- c("ww", "ee", "ff", "uu", "kk"), what will be the output for x[(c(2,3)]? a. "ee", "ff" b. "ee" c. "ff" ...
1968 sym
Factor exercises
In the exercises below we cover the basics of factors. Before proceeding, first read chapter 4 of An Introduction to R, and the help pages for the cut, and table functions. Answers to the exercises are available here. Exercise 1 If x = c(1, 2, 3, 3, 5, 3, 2, 4, NA), what are the levels of factor(x)? a. 1, 2, 3, 4, 5 b. NA c. 1, 2, 3, 4, 5, NA Ex...
3180 sym
List exercises
In the exercises below we cover the basics of lists. Before proceeding, first read section 6.1-6.2 of An Introduction to R, and the help pages for the sum, length, strsplit, and setdiff functions. Answers to the exercises are available here. Exercise 1 If: p <- c(2,7,8), q <- c("A", "B", "C") and x <- list(p, q), then what is the value of x[2]? a...
2209 sym
Data frame exercises
In the exercises below we cover the basics of data frames. Before proceeding, first read section 6.3.1 of An Introduction to R, and the help pages for the cbind, dim, str, order and cut functions. Answers to the exercises are available here. Exercise 1 Create the following data frame, afterwards invert Sex for all individuals. Exercise 2 Create ...
3116 sym 4 img
Reading delimited data
In the exercises below we cover the basics of reading delimited data. Before proceeding, first read section 7.1 of An Introduction to R, and the help pages for the read.table function. Answers to the exercises are available here. For each exercise we provide a data set that can be accessed through the link shown in the exercise. You can read the ...
2325 sym
Scan exercises
In the exercises below we cover the basics of the scan function. Before proceeding, first read section 7.2 of An Introduction to R. Answers to the exercises are available here. For each exercise we provide a data set that can be accessed through the link shown in the exercise. You can scan the data from this link directly (clicking on it will sho...
1510 sym