One of reasons to use R is to avoid using Excel for complex data processing. But, this does not mean one should not use Excel at all. There are some good reasons for it, including communication with non-coding co-workers being probably the most important of them all. To ensure smoothness of workflow consisting of analysis […]
Create XLSX Files With R – Part 2: Solutions
Below are the solutions to these exercises on “Creating XLSX Files – Part 2.” #################### # # # Exercise 1 # # # #################### library(openxlsx) wb <- createWorkbook() #################### # # # Exercise 2 # # # #################### options(“openxlsx.numFmt” = “0.00”) #################### # # # Exercise 3 # # # #################### addWorksheet(wb, sheetName = ‘Iris’) […]
Create XLSX Files With R – Part 1: Exercises
One of reasons to use R is to exclude using Excel for complex data processing. But, this does not mean one should not use Excel at all. There are some good reasons for it. For example, communication with non-coding co-workers being probably the most important of them all. To ensure smoothness of workflow consisting of […]
Create XLSX Files with R – Part 1: Solutions
Below are the solutions to these exercises on “Creating Xlsx Files.” #################### # # # Exercise 1 # # # #################### library(openxlsx) write.xlsx(iris, ‘iris.xlsx’) #################### # # # Exercise 2 # # # #################### write.xlsx(list(mtcars = mtcars, iris = iris), ‘mtcars_iris.xlsx’) #################### # # # Exercise 3 # # # #################### write.xlsx(iris, ‘iris.xlsx’, borders = […]
Practice Your ggplot Skills: Exercises
ggplot2 is a great tool for complex data visualization. Let’s practice it a bit! Answers to these exercises are available here. For each exercise, please replicate the given graph. Some exercises require additional data wrangling. If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your […]
Practice Your ggplot Skills: Solutions
Below are the solutions to these exercises on “ggplot.” #################### # # # Exercise 1 # # # #################### library(tidyverse) iris %>% ggplot(aes(Sepal.Length, Sepal.Width, color = Species, shape = Species)) + geom_point() + geom_density2d() + ggtitle(‘IRIS’) + theme_light() #################### # # # Exercise 2 # # # #################### iris %>% mutate(Species = ‘ALL’) %>% bind_rows(iris) […]
Tidy Model Results: Exercises
Common problems with complex modeling analysis with R is that model results are often complex objects and getting to values, like model coefficients, demand a lot of manipulations; others vary from one model to another. Fortunately, the broom package provides nice and easy to use solutions to the problem. Answers to the exercises are available here. […]
Tidy Model Results: Solutions
Below are the solutions to these exercises on “Tidyverse Ways of Summarizing Model’s Findings.” #################### # # # Exercise 1 # # # #################### library(tidyverse) library(broom) mpg_lm <- lm(mpg ~ disp, mtcars) tidy(mpg_lm) ## term estimate std.error statistic p.value ## 1 (Intercept) 29.59985476 1.229719515 24.070411 3.576586e-21 ## 2 disp -0.04121512 0.004711833 -8.747152 9.380327e-10 #################### # […]
Tidy Date/Times: Exercises
Manipulating dates and times is usually quite hard and confusing. When time zones come in, it gets even harder; but still, sometime one needs to process date-time objects in their code. Lubridate is one of a few great packages which makes things a bit easier. Answers to the exercises are available here. Please, do all […]
Tidy Date/Times: Solutions
Below are the solutions to these exercises on “Tidyverse Ways of Modeling.” #################### # # # Exercise 1 # # # #################### library(lubridate) Sys.setlocale(“LC_ALL”,”English”) ## [1] “LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252” my_date <- mdy(’01-31-2018′) my_date ## [1] “2018-01-31” #################### # # # Exercise 2 # # # #################### leap_year(my_date) ## [1] FALSE #################### # # […]