Articles by r-exercises

Higher Order Functions Exercises

August 5, 2016 | r-exercises

Higher order functions are functions that take other functions as arguments or return functions as their result. In this set of exercises we will focus on the former. R has a set of built-in higher order functions: Map, Reduce, Filter, Find, Position, Negate. They enable us to complete complex operations ... [Read more...]

Start here to learn R!

July 22, 2016 | r-exercises

Ready, set, go! On R-exercises, you will find hundreds of exercises that will help you to learn R. We’ve bundled them into exercise sets, where each set covers a specific concept or function. An exercise set typically contains about 10 exercises, progressing from easy to somewhat more difficult. In order ... [Read more...]

Get-your-stuff-in-order exercises

March 1, 2016 | r-exercises

In the exercises below we cover the basics of ordering vectors, matrices and data frames. We consider both column-wise and row-wise ordering, single and multiple variables, ascending and descending sorting, and sorting based on numeric, character and factor variables. Before proceeding, it might be helpful to look over the help ... [Read more...]

Bind exercises

February 22, 2016 | r-exercises

Binding vectors, matrices and data frames using rbind and cbind is a common R task. However, when dimensions or classes differ between the objects passed to these functions, errors or unexpected results are common as well. Sounds familiar? Time to practice! Answers to the exercises are available here. Exercise 1 Try ... [Read more...]

Practical uses of R object modes: some examples

February 16, 2016 | r-exercises

One of our readers commented on our mode exercises post: “What real world tasks are you using mode to solve?” I think it’s an interesting question, from a somewhat larger perspective. Obviously, it’d be a waste of time to learn all kinds of obscure commands that don’t ... [Read more...]

Mode exercises

February 14, 2016 | r-exercises

In the exercises below we cover the basics of R object modes. Understanding mode is important, because mode is a very basic property of any R object. Practically, you’ll use the mode property often to convert e.g. a character vector to a numeric vector or vice versa. Before ... [Read more...]

functions exercises

February 7, 2016 | r-exercises

Today we’re practising functions! In the exercises below, you’re asked to write short R scripts that define functions aimed at specific tasks. The exercises start at an easy level, and gradually move towards slightly more complex functions. Answers to the exercises are available here. If you obtained a ... [Read more...]

Conditional execution exercises

January 26, 2016 | r-exercises

In the exercises below we cover the basics of conditional execution. In all previous exercises, the solutions required one or more R statements that were all executed consecutively. In this series of exercises we’re going to use the if, else and ifelse functions, to execute only a subset of ... [Read more...]

Scan exercises

January 11, 2016 | r-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 ... [Read more...]

Reading delimited data

January 7, 2016 | r-exercises

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 ... [Read more...]

Data frame exercises

January 4, 2016 | r-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 ... [Read more...]

List exercises

December 31, 2015 | r-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... [Read more...]

Factor exercises

December 28, 2015 | r-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 […] [Read more...]

Index vectors

December 21, 2015 | r-exercises

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 [Read more...]

Character vector exercises

December 18, 2015 | r-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 [Read more...]

Missing values

December 14, 2015 | r-exercises

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 [Read more...]

Array exercises

December 1, 2015 | r-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 […] [Read more...]
1 2

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)