Below are the solutions to these exercises on data.table. library(data.table) library(ggplot2) ############### # # # Exercise 1 # # # ############### iris_dt <- as.data.table(iris) iris_dt[,mean(Petal.Length),substr(Species,1,1)] ## substr V1 ## 1: s 1.462 ## 2: v 4.906 ############### # # # Exercise 2 # # # ############### dt <- as.data.table(diamonds) dt[,("mean_price"= mean(price)),.(cut,color)] ## cut color V1 […]

## Data Manipulation with Data Table -Part 1

In the exercises below we cover the some useful features of data.table ,data.table is a library in R for fast manipulation of large data frame .Please see the data.table vignette before trying the solution .This first set is intended for the begineers of data.table package and does not cover set keywords, joins of data.table which […]

## A Primer in functional programming in R Solutions (Part-2)

Below are the solutions to this exercise on the part 2 of the series on functional programming in R . library(purrr) ############### # # # Exercise 1 # # # ############### funcs = list("mean"= mean,"Median"= median,"STD" = sd) ## funcs is a list of functions . This is a useful application of list of functions […]

## A Primer in functional Programming in R (part -2)

In the last exercise, We have seen how powerful functional programming principles can be and how it can drammatically increase the readablity of the code and how easily you can work with them .In this set of exercises we will look at functional programming principles with purrr.Purrr comes with a number of interesting features and […]

## A Primer in Functional Programming in R (Part – 1)

In the exercises below we cover the basics of functional programming in R( part 1 of a two series exercises on functional programming) . We consider recursion with R , apply family of functions , higher order functions such as Map ,Reduce,Filter in R . Answers to the exercises are available here. If you obtained […]

## A Primer in functional programming in R Solutions (Part-1)

Below are the solutions to these exercises on Functional Programming. #################### # # # Exercise 1 # # # #################### factorial_reduce <- function(n){ stopifnot( n>=0) if(n==0){ return(1) } else{ Reduce(`*`,as.numeric(n:1)) } } #################### # # # Exercise 2 # # # #################### factorial_memoized <- function (n){ stopifnot((n>=0)) ret_value <- NA if(n==0){ return(1) } mem_vect <- […]