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 […]
Exercises (beginner)
Logical vectors and operators
Before you start, enter the following code: data <- mtcars Solutions are available here. Exercise 1 Use logical operators to output only those rows of data where column mpg is between 15 and 20 (excluding 15 and 20). Exercise 2 Use logical operators to output only those rows of data where column cyl is equal […]
Regular sequences
Before proceeding, please review Chapter 2 of An Introduction to R and the internal R Documentation for the seq() function (type ?seq in the R console). Solutions are available here. Excercise 1 Using the seq() function, generate the sequence 2, 5, 8, 11. Exercise 2 Use the seq() function to generate the sequence 9, […]
Vector exercises
A vector is a simple data structure in R. You will use it frequently, often as a building block of more complex data structures and operations on those structures. Before proceeding, please follow our short tutorial and review Chapter 2 of An Introduction to R. First, write down your answer, without using R and without […]