Blog Archives

Converting Individual Binary vectors to a Value based on Column Names

May 7, 2019
By

When processing data downloaded from popular survey engines, it’s not uncommon for multiple choice questions to be represented as one column per possible response coded as 0/1. So, a question with just two responses might be downloaded as part of a CSV with one column for q1_1 and another for q1_2. If the responses are … Continue reading Converting...

Read more »

Common Uncommon Notations that Confuse New R Coders

April 17, 2019
By

Here are a few of the more commonly used notations found in R code and documentation that confuse coders of any skill level who are new to R. Be aware that any variable name that begins with a . is usually hidden from view, so won’t be seen in the Environment pane in RStudio or … Continue reading Common...

Read more »

The Shiny Module Design Pattern

January 21, 2019
By

Foremost in your mind should be the quintessential reality of R: Everything that happens in R is the result of a function call. Shiny is no exception. To write a minimal shiny app, you create an object that describes your app’s user interface, write a function describing runtime behaviors, and pass them into a function … Continue reading The...

Read more »

Writing Pipe-friendly Functions

July 8, 2018
By

Pipes have been a fundamental aspect of computer programming for many decades. In short, the semantics of pipes can be thought of as taking the output from the left-hand side and passing it as input to the right-hand side. For example, in a linux shell, you might cat example.txt | unique | sort to take … Continue reading Writing...

Read more »

Three Deep Truths About R

June 29, 2018
By

Everything that exists in R is an object ~ John M. Chambers Everything that happens in R is the result of a function call ~ John M. Chambers Names have objects; objects don’t have names ~ Hadley Wickham So, what are the implications of these statements? Everything in R is an object NULL is an … Continue reading Three...

Read more »

I’m ‘not in’ right now…

April 29, 2018
By

Checking whether an item is in a vector or not in a vector is a common task. The notation in R is a little inelegant when expressing the “not in” condition since the negation operator (!) is separated from the … Continue reading →

Read more »

Defensively install packages in R

February 19, 2018
By

Often, your R code will rely on having one or more R packages available. A little defensive coding will save users of your code—including future-you—from having to figure out which packages you’re using and then having to manually install them. This … Continue reading →

Read more »

Getting started with R

February 19, 2018
By

Download and install R. Download and install RStudio. Read R for Data Science. R provides the backend: the programming language specification and the interpreter. RStudio provides the frontend: the user interface that allows you to interact with R, visualize data, … Continue reading →

Read more »

FizzBuzz in R

May 14, 2017
By

Functions are first class objects in R. Functions establish closures also known in R as environments. So, you can use functions to create other functions in creative ways. Here, I’ve written a function called divisor that returns a function that checks whether a given input, d, is evenly divisible by number and if so, returns string. Then I … Continue reading FizzBuzz...

Read more »

Search R-bloggers

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)