This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
) %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load packages ---------------------------------------------------------------- | |
library(shiny) | |
library(shinythemes) | |
library(ggplot2) | |
library(dplyr) | |
library(fiftystater) | |
library(tools) | |
library(mapproj) | |
library(fontawesome) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
# list col for age -------------------------------------------------- | |
df_listcol <- tibble( | |
age = list(30, 40, 50, 55, "65+") | |
) | |
typeof(df_listcol$age) | |
#> [1] "list" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(ggplot2) | |
dataset <- diamonds | |
ui <- pageWithSidebar( | |
headerPanel("Diamonds Explorer"), | |
sidebarPanel( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 ------------ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. | |
) |