Below are the solutions to these exercises on answering probability questions with simulation. #################### # # # Exercise 1 # # # #################### # This is a famous problem covered in a recent episode of Numberphile # https://www.youtube.com/embed/pbXg5EI5t4c matched <- function(highest_card) { cards_ordered <- 1:highest_card # shuffle cards and layout # check if any matches […]

# Solutions

## R with remote databases Solutions (Part-2)

Below are the solutions to these exercises on using R with remote databases. #################### # # # Exercise 1 # # # #################### library(dplyr) library(dbplyr) library(DBI) library(RSQLite) library(nycflights13) con <- dbConnect(SQLite(), path = ":memory:") copy_to(con, flights, name = ‘flights’, temporary = FALSE) copy_to(con, flights, name = ‘flights_idx’, temporary = FALSE, indexes = list("carrier")) #################### # […]

## Generalized linear models solution(Beginners)

Below are the solutions to these exercises on generalized linear models. if (!’titanic’ %in% installed.packages()) install.packages(‘titanic’) library(titanic) ## Warning: package ‘titanic’ was built under R version 3.3.3 DATA <- titanic_train[,-c(1,4,9,11)] #################### # # # Exercise 1 # # # #################### (lm_reg <- lm(formula = Survived ~ Age + Fare, data = DATA)) ## ## Call: […]

## Applying machine learning algorithms – exercises: solutions

Below are the solutions to these exercises on applying machine learning to your dataset. #################### # # # Exercise 1 # # # #################### install.packages(“caret”) library(caret) data(iris) validation <- createDataPartition(iris$Species, p=0.80, list=FALSE) validation20 <- iris[-validation,] iris <- iris[validation,] library(caret) control <- trainControl(method=”cv”, number=10) #################### # # # Exercise 2 # # # #################### library(caret) control […]

## Probability functions advanced solutions

Below are the solutions to these exercises on probability functions. if (!’MASS’ %in% installed.packages()) install.packages(‘MASS’) library(MASS) #################### # # # Exercise 1 # # # #################### set.seed(1) random_numbers <- runif(100, min = .5, max = 6.5) (round(random_numbers)) ## [1] 2 3 4 6 2 6 6 4 4 1 2 2 5 3 5 3 […]

## Data wrangling : Cleansing – Regular expressions (3/3) Solutions

Below are the solutions to these exercises on data cleansing. ## Error in contrib.url(repos, type): trying to use CRAN without setting a mirror #################### # # # Exercise 1 # # # #################### grep("Merc", rownames(mtcars), value = TRUE) ## [1] "Merc 240D" "Merc 230" "Merc 280" "Merc 280C" "Merc 450SE" ## [6] "Merc 450SL" "Merc […]

## Working with air quality and meteorological data exercises part 3: Solutions

Below are the solutions to these openair exercises ############### # # # Exercise 1 # # # ############### timeVariation(subset(my1data), pollutant = "o3", ylab = "o3 (ppb)") timeVariation(subset(my1data), pollutant = "pm10", ylab = "pm10 (ug/m3") ############### # # # Exercise 2 # # # ############### timeVariation(subset(my1data, ws > 3 & wd > 100 & wd < […]

## Big Data analytics with RevoScaleR Exercises-2-Solutions

Below are the solutions to these exercises on RevoScaleR library(RevoScaleR) inFile <- "ccFraud.csv" inFilexdf <- "ccFraud.xdf" rxImport( inData = inFile, outFile = inFilexdf, overwrite = TRUE) ############### # # # Exercise 1 # # # ############### rxDataStep(airquality,outFile = "airquality.xdf",overwrite = TRUE) ############### # # # Exercise 2 # # # ############### rxLinePlot(balance~numTrans,inFilexdf,rowSelection = (numTrans >50 […]

## R with remote databases Solutions (Part-1)

Below are the solutions to these exercises on usage of R with remote databases. #################### # # # Exercise 1 # # # #################### library(dplyr) library(dbplyr) library(DBI) library(RSQLite) library(nycflights13) con <- dbConnect(SQLite(), path = ":memory:") #################### # # # Exercise 2 # # # #################### copy_to(con, flights, name = ‘flights’, temporary = FALSE) copy_to(con, planes, […]

## Hacking statistics or: How I Learned to Stop Worrying About Calculus and Love Stats Solutions (Part-8)

Below are the solutions to these exercises on conditional probability. #################### # # # Exercise 1 # # # #################### #1 library(VennDiagram) data.ex1<-read.csv(“http://www.r-exercises.com/wp-content/uploads/2017/09/data.ex1_.set8_.csv”) str(data.ex1) ## ‘data.frame’: 34 obs. of 3 variables: ## $ X : int 1 2 3 4 5 6 7 8 9 10 … ## $ Graphic : int 1 1 0 […]