Solution 1 Part a x <- 157:164 x ## [1] 157 158 159 160 161 162 163 164 Part b x <- c(15:18, 20:24) x ## [1] 15 16 17 18 20 21 22 23 24 Part c x <- 10:1 x ## [1] 10 9 8 7 6 5 4 3 2 1 Part […]

# Solutions

## Vectors and Functions Solutions

Solution 1 v <- c(length(rivers), sum(rivers), mean(rivers), median(rivers), var(rivers), sd(rivers), min(rivers), max(rivers)) v ## [1] 141.0000 83357.0000 591.1844 425.0000 243908.4086 493.8708 ## [7] 135.0000 3710.0000 Back to exercise Solution 2 The trim=0.25 argument means that R will ignore 25 percent of the 8 observations (i.e., 2 observations) from both the lowest and highest end. So, […]

## Working With Vectors Solutions

Solution 1 u <- 4 v <- 8 u + v ## [1] 12 u – v ## [1] -4 u * v ## [1] 32 u / v ## [1] 0.5 u^v ## [1] 65536 Back to exercise Solution 2 u <- c(4, 5, 6) v <- c(1, 2, 3) u + v ## […]

## Creating Vectors Solutions

Please find below the solutions for the first 5 exercises of our set Creating vectors. The solutions for exercise 6, 7 and 8 are available in our eBook Start Here To Learn R – vol. 1: Vectors, arithmetic, and regular sequences. Solution 1 100 ## [1] 100 Back to exercise Solution 2 c(2, 4, 6, 8, […]

## Modularize your Shiny Apps: Solutions

[emaillocker]Below are the solutions to these exercises on Shiny modules. # load package library(shiny) #################### # # # Exercise 1 # # # #################### q1_module_UI <- function(id) { ns <- NS(id) selectInput( inputId = ns(“letter”), label = “Select a letter”, choices = LETTERS ) } #################### # # # Exercise 2 # # # #################### […]

## Prettify your Shiny Tables with DT: Solutions

[emaillocker]Below are the solutions to these exercises on the DT package. # load packages library(shiny) library(DT) # Each exercises should result in a Shiny app, # where the changing part is the renderDataTable() function. # To save time, you can use the following template, # and just replace the <renderDataTable> placeholder for each exercise. # […]

## Pull the Right Strings with stringr: Solutions

[emaillocker]Below are the solutions to these exercises on stringr. # load package library(stringr) # prepare the exercises data addresses <- c(“14 Pine Street, Los Angeles”, “152 Redwood Street, Seattle”, “8 Washington Boulevard, New York”) products <- c(“TV “, ” laptop”, “portable charger”, “Wireless Keybord”, ” HeadPhones “) long_sentences <- stringr::sentences[1:10] field_names <- c(“order_number”, “order_date”, “customer_email”, […]

## Step Up Your Dashboard With Shinydashboard – Part 2: Solutions

[emaillocker] Below are the solutions to these exercises on the “Shinydashboard Package – Part 2.” # load packages library(shiny) library(shinydashboard) ################################## # # # Basic Code to Start With # # # ################################## header <- dashboardHeader( title = span( “Practicing shinydashboard”, style = “font-family: Tahoma; font-weight: bold” ), titleWidth = “300px” ) sidebar <- dashboardSidebar( […]

## Step Up Your Dashboard With Shinydashboard – Part 1: Solutions

[emaillocker]Below are the solutions to these exercises on the “Shinydashboard Package – Part 1.” # load packages library(shiny) library(shinydashboard) #################### # # # Exercise 1 # # # #################### header <- dashboardHeader( title = span( “Practicing shinydashboard”, style = “font-family: Tahoma; font-weight: bold” ) ) #################### # # # Exercise 2 # # # #################### […]

## Specialize in Geo-Spatial Visualizations With Leaflet – Part 2: Solutions

Below are the solutions to these exercises on Leaflet Package – Part 2.” # load package library(leaflet) #################### # # # Exercise 1 # # # #################### leaflet() %>% setView(lng = -47.4, lat = 39.75, zoom = 3) %>% addTiles() %>% addEasyButton( easyButton( icon = shiny::icon(“home”), title= “Reset Zoom”, onClick = JS( c(“function(btn, map) {map.setView(new […]