Skip to content

Instantly share code, notes, and snippets.

View IndrajeetPatil's full-sized avatar
🎯
Focusing

Indrajeet Patil IndrajeetPatil

🎯
Focusing
View GitHub Profile
@IndrajeetPatil
IndrajeetPatil / pass_by.cpp
Created January 11, 2022 15:13
Passing by value versus reference
#include <iostream>
void passValue(int x)
{
x += 2;
}
void passRef(int &x)
{
x += 2;
@IndrajeetPatil
IndrajeetPatil / multiple_case_when
Created October 24, 2021 15:13
Alternative to `case_when` when multiple conditions present
library(dplyr, warn.conflicts = FALSE)
l <- letters[1:3]
n <- 1:3
df <- tibble(x = c(rep(l, 2), "x"))
# thanks to Bret Beheim
df %>% mutate(y = n[match(x, l)])
# thanks to Lisa DeBruine and Brenton Wiernik
# code for this tweet:
# https://twitter.com/patilindrajeets/status/1379114056590708736?s=20
library(ggstatsplot)
library(gginnards)
df <-
data.frame(
"time-1" = c("Disease", "Disease", "No Disease", "Disease", "Disease"),
"time-2" = c("Disease", "Disease", "No Disease", "No Disease", "No Disease")
# setup
set.seed(123)
library(ggplot2)
library(ggrepel)
library(forcats)
# data
(df <- structure(
list(
cyl = structure(
@IndrajeetPatil
IndrajeetPatil / fdi_arab_spring.R
Last active February 23, 2020 19:49
How foreign investment in the middle-east collapsed after the revolution
# setup
set.seed(123)
library(tidyverse)
library(hrbrthemes)
library(ggplot2)
library(ggrepel)
# make the dataframe
df <-
tibble::tribble(
library(tidyverse)
iris %>%
tibble::as_tibble(.) %>%
dplyr::mutate(., row_mean = pmap_dbl(list(Sepal.Length, Sepal.Width), mean))
#> # A tibble: 150 x 6
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species row_mean
#> <dbl> <dbl> <dbl> <dbl> <fct> <dbl>
#> 1 5.1 3.5 1.4 0.2 setosa 5.1