Home ยป r

r

Starting a remote Selenium server in R

In this brief article, I explain how you can run a Selenium server, right from within your R code. This allows you to not manually open and run a Selenium command in your command prompt. This code has been tested on a Win11 machine. Prerequisites To run Selenium from within…

How to set the package directory in R

When I got my new company computer, out service desk installed R in a network folder, which made installing and loading R libraries extremely slow. That’s why I reinstalled R and needed to set my library directory explicitly, so that R doesn’t look in the network folder with every package…

Calculating the number of days between two dates in R is as simple as using + or -. However, if you only want to count the business days (e.g. in a B2B context), you’ll have to be a little more creative. Let’s just do that. Count business days in R…

Scale ggplot2 Y-Axis to millions (M) or thousands (K) in R

In this blog post we’ll tackle an aesthetic aspect in R & ggplot2 — namely, displaying your the labels on your axis as millions or thousands. Assume, you have a data set with a column that has numbers ranging into the millions. To emulate this, I loaded the mtcars dataset…

How to read ZIP files in R

In this blog post I discuss how you can load compressed CSV files, such as .zip and .tar.gz. Nowadays, many packages support it and we’ll go over the different methods. When data sets are ping-ponged across an organization, in order to limit network and storage usage, they often come in…

How to add confidence intervals to a line in ggplot2 (R)

In this blog post, you’ll learn how to add confidence intervals to a line plot in R in the popular ggplot2 visualization package, part of the tidyverse. First, let’s create some random data to work with. For demonstrational purposes, I’ve created two time series from two normally-distributed random variables. These…

How to load a single function from an R library

For the R users that are jealous of Python’s import system, there’s good news. As of R 3.6, it’s possible to include or exclude specific functions when loading a library. Importing the whole namespace is no longer required. Selective loading of R packages As of R 3.6, importing only one…

Classification in R: Confusion Matrix

One of the most fundamental tools for evaluating classifiers is the confusion matrix. In this blog post, I elaborate on how to generate a confusion matrix in R using the tidymodels ecosystem. First, I create a classifier to predict the income class for the very popular adult data set. From…

R: Filter a data frame on multiple partial strings

This is a blog post about a very specific topic. I wanted to filter a data frame on a set of strings that I wanted to match partially. Let’s dive right in. Matching partially is fairly easy, and there are many libraries to choose from, with grepl and str_detect the…

Connect to a Selligent API endpoint in R

Selligent is an ecosystem of marketing tools, mostly known for it’s marketing automation platform formerly known as Campaign. I was never a big fan of Selligent because it used to be a very closed ecosystem. However, it made available a wide range of APIs recently, allowing you to query its…