Skip to content

Instantly share code, notes, and snippets.

View bobaekang's full-sized avatar

Bobae Kang bobaekang

View GitHub Profile
@bobaekang
bobaekang / faster-ifelse-in-base-r.md
Created October 23, 2018 21:13
Faster `ifelse()` in base R

Summary

A faster base R alternative to ifelse().

Main

Introducing ifelse()

ifelse() is a base R function that takes a logical test vector, a value if test is TRUE and a value if test is FALSE. It can be thought as "vectorized" if-else, which takes a vector as an input, tests each of its elements using some criteria and returns another vector whose elements are based on the test result for each element of the input vector.

Here is a simple example where ifelse() returns "one" if a vector element equals 1, and "not one" otherwise:

@bobaekang
bobaekang / creating-custom-functions-for-data-manipulation-r.md
Last active October 3, 2018 16:40
Creating custom functions for data manipulation in R

Summary

Creating custom functions to streamline a series of operations involving tidyverse functions.

Main

R function basics

One of the key skills in R programming involves creating custom functions to encapsulate complicated and repeated tasks or operations. Custom functions with clear and descriptive names enable us to write our R code in a concise and intuitive fashion.

The basics of defining a function in R are as follows:

  1. Use function() to define a new function
  2. Write the function body consisting of R expressions to be evaluated
@bobaekang
bobaekang / becoming-rstudio-ide-power-user.md
Last active October 3, 2018 16:41
Becoming RStudio IDE power user

Summary

Two useful RStudio IDE functionalities to improve your day-to-day R programming workflow--and more.

Main

The RStudio IDE (integrated development environment) is a powerful open-source application that is a de facto standard tool in the R community for writing programs and developing software. Although many casual R users are unaware of them, the RStudio IDE is in fact packed with useful functionalities that can significantly improve your programming workflow.

Here I present two such functionalities, namely, keyboard shortcuts and code snippets.

1. Keyboard shorcuts

RStudio IDE offers a large number of keyboard shortcuts to help you to quickly carry out some common tasks. Some of the keyboard shortcuts I find useful are as follows: