Skip to content

Instantly share code, notes, and snippets.

View mine-cetinkaya-rundel's full-sized avatar

Mine Cetinkaya-Rundel mine-cetinkaya-rundel

View GitHub Profile
@mine-cetinkaya-rundel
mine-cetinkaya-rundel / mutate_if.R
Last active November 21, 2018 07:13
Use mutate_if to not repeat yourself
library(tidyverse)
# mutate -----------------------------------------------------------------------
iris %>%
mutate(
Sepal.Length_cat = ifelse(Sepal.Length < mean(Sepal.Length), "below mean", "at or above mean"),
Sepal.Width_cat = ifelse(Sepal.Width < mean(Sepal.Width), "below mean", "at or above mean"),
Petal.Length_cat = ifelse(Petal.Length < mean(Petal.Length), "below mean", "at or above mean"),
Petal.Width_cat = ifelse(Petal.Width < mean(Petal.Width), "below mean", "at or above mean")
) %>%
@mine-cetinkaya-rundel
mine-cetinkaya-rundel / life_locs.R
Last active November 19, 2018 13:35
Plotting and finding distances between places lived
# load packages ----------------------------------------------------------------
library(ggmap) # for geocoding cities, need v2.7 from https://github.com/dkahle/ggmap
library(fields) # for finding distance between two points
library(maps) # for world map
library(geosphere) # for connecting dots
# geocode cities lived ---------------------------------------------------------
ist <- geocode("Istanbul, Turkey")
nyc <- geocode("New York, NY, USA")
lax <- geocode("Los Angeles, CA, USA")
# Load packages ----------------------------------------------------------------
library(shiny)
library(shinythemes)
library(ggplot2)
library(dplyr)
library(fiftystater)
library(tools)
library(mapproj)
library(fontawesome)
library(tidyverse)
library(rtweet)
library(glue)
tml <- get_timelines("CostcoRiceBag", n = 3200)
br <- tml %>%
filter(is.na(reply_to_screen_name)) %>%
slice(
which(str_detect(text, "IS IT JUST ME")):
library(tidyverse)
# list col for age --------------------------------------------------
df_listcol <- tibble(
age = list(30, 40, 50, 55, "65+")
)
typeof(df_listcol$age)
#> [1] "list"
@mine-cetinkaya-rundel
mine-cetinkaya-rundel / model-parallel-lines.R
Created March 1, 2018 03:36
Plotting parallel regression lines
# Fit model with parallel lines (main effects only)
m_pr <- lm(log(price) ~ Surface + factor(artistliving), data = pp_Surf_lt_5000)
## Option 1
# Save regression coefficients in a tibble
m_pr_coefs <- m_pr %>%
tidy() %>%
select(term, estimate)
@mine-cetinkaya-rundel
mine-cetinkaya-rundel / app.R
Created August 9, 2017 21:47
Sample Shiny application demonstrating usage of Shiny Server Pro's authentication feature to customize the app according to the privileges of the logged-in user.
library(shiny)
library(ggplot2)
## Pre-app calculations
# Get the current day of the month
dom <- 25
# Define the target for salespeople in our organization.
salesTarget <- 15000
@mine-cetinkaya-rundel
mine-cetinkaya-rundel / app.R
Created June 27, 2017 21:43
Shiny example: Diamonds Explorer
library(shiny)
library(ggplot2)
dataset <- diamonds
ui <- pageWithSidebar(
headerPanel("Diamonds Explorer"),
sidebarPanel(
# Could this be an alternative solution for the following?
# https://github.com/jcheng5/rstudio2017-shiny-workshop/blob/master/apps/reactivity/cranlogs.solution.R
library(cranlogs)
library(dplyr)
library(lubridate)
library(ggplot2)
library(shiny)
# Define UI for specifying package and plotting cranlogs ------------
@mine-cetinkaya-rundel
mine-cetinkaya-rundel / app.R
Last active March 21, 2023 15:16
Shiny dynamic UI - observers & lapply
# An example based on http://shiny.rstudio.com/articles/dynamic-ui.html
library(shiny)
ui = basicPage(
fluidRow(
actionButton(inputId = "add_buttons", label = "Add 5 Buttons")
),
uiOutput("more_buttons") # this is where the dynamically added buttons will go.
)