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://r-exercises.com/wp-content/uploads/2015/12/scan01.txt") # Exercise 2 # a) vec <- scan("http://r-exercises.com/wp-content/uploads/2015/12/scan02.txt") # b) matrix <- matrix(scan("http://r-exercises.com/wp-content/uploads/2015/12/scan02.txt"), nrow=10) # Exercise 3 v <- scan("http://r-exercises.com/wp-content/uploads/2015/12/scan03.txt", what="character") # Exercise 4 mat <- matrix(scan("http://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 […]

## Reading delimited data: solutions

Below are the solutions to these exercises on reading delimited data. # Exercise 1 df <- read.table("http://r-exercises.com/wp-content/uploads/2015/12/Table0.txt") df ## V1 V2 V3 V4 V5 ## 1 Alex 25 177 57 F ## 2 Lilly 31 163 69 F ## 3 Mark 23 190 83 M ## 4 Oliver 52 179 75 M ## 5 Martha […]

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