We just added this week’s set of bonus exercises! Bonus exercises are weekly exercises sets, available to subscribers to our weekly newsletter. Please sign up using the form on the right, and receive further details by email how to download the bonus exercises (and solutions, of course). This week’s bonus exercises aim to practise building […]

## Bonus: Avoiding for-loops exercises

We just added our first set of bonus exercises! Bonus exercises are weekly exercises sets, available to subscribers to our weekly newsletter. Please sign up using the form on the right, and receive further details by email how to download the bonus exercises (and solutions, of course). This week’s bonus exercises aim to practise vectorization, […]

## Big Salaries, Recommendation Systems, and Where We’ll Be 5 Years from Now

To stay on top of R in the news, we’re sharing some stories related to R published last week. Why Data Science ‘Rock Stars’ Earn Big Salaries (Dennis McCafferty) Recent post and slide deck related to the 2016 Data Science Salary Survey (O’Reilly Media), with R mentioned as one of the high-demand programming languages (next […]

## Start here to learn R!

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 to give you a full […]

## functions exercises

Today we’re practicing 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 different solution than the one posted on […]

## functions exercises: solutions

Below are the solutions to these exercises on functions. If you obtained a different (smarter, vectorized, etc) solution, please post as a comment below. # Exercise 1 f.sum <- function (x, y) { r <- x + y r } f.sum(5, 10) ## [1] 15 # Exercise 2 f.exists <- function (v, x) { exist […]

## Conditional execution 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 the R script, depending on one […]

## Conditional execution exercises: solutions

Below are the solutions to these exercises on conditional execution. # Exercise 1 x <- -10 abs <- x if (x < 0) { abs = -x } cat("The absolute value of ", x, " is ", abs , "\n" ) ## The absolute value of -10 is 10 # Exercise 2 x <- 16 […]

## Scan exercises: solutions

Below are the solutions to these exercises on the scan function. # Exercise 1 v <- scan("http://www.r-exercises.com/wp-content/uploads/2015/12/scan01.txt") # Exercise 2 # a) vec <- scan("http://www.r-exercises.com/wp-content/uploads/2015/12/scan02.txt") # b) matrix <- matrix(scan("http://www.r-exercises.com/wp-content/uploads/2015/12/scan02.txt"), nrow=10) # Exercise 3 v <- scan("http://www.r-exercises.com/wp-content/uploads/2015/12/scan03.txt", what="character") # Exercise 4 mat <- matrix(scan("http://www.r-exercises.com/wp-content/uploads/2015/12/scan04.txt", sep="\t", nlines=5), ncol=2) df <- as.data.frame(mat) # Exercise 5 list <- […]

## 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 […]