Skip to content

Instantly share code, notes, and snippets.

View RamiKrispin's full-sized avatar
👻
Focusing

Rami Krispin RamiKrispin

👻
Focusing
View GitHub Profile
library(TSstudio)
# Loading the data
data(USgas)
# Creating lags
df <- ts_to_prophet(USgas)
# Will use the seasonal lag (12) of the series
df$y_12 <- dplyr::lag(df$y, n = 12)
@RamiKrispin
RamiKrispin / Astronauts.R
Created September 2, 2020 03:28
Adding text and title
#===================================================================================================================
# Author: Aloysius Ong
# Dataset: #tidytuesday - Astronauts
# Purpose: Visualization
#===================================================================================================================
astronauts <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-07-14/astronauts.csv')
library(plotly)
library(dplyr)
@RamiKrispin
RamiKrispin / get_seasonality_type.R
Created September 5, 2020 12:29
Extract from tsibble object the seasonality type
ts.obj <- tsibble::tourism
int <- vctrs::vec_data(base::attributes(ts.obj)$interval)
s <- NULL
for(i in names(int)){
if(int[[i]] == 1){
s <- i
snippet dd
devtools::document()
snippet m
`%>%` <- magrittr::`%>%`
snippet l
lubridate::
snippet >
%>%
snippet t
TSstudio::
@RamiKrispin
RamiKrispin / psicommunity_data.R
Created December 26, 2020 22:57
Parsing data with multiple seperators
# Set the file name
file_name <- "https://raw.githubusercontent.com/VIS-SIG/Wonderful-Wednesdays/master/data/2020/2020-12-09/Reexcision.csv"
# Read the unparsed table
x <- readLines(con <- file(file_name))
# Parse the table names
z <- unlist(strsplit(x[1], ";", fixed = TRUE))
z <- unlist(strsplit(x[1], '\"'))
x_names <- z[which(z !=";" & z != "")]
@RamiKrispin
RamiKrispin / bar_plot.R
Last active December 30, 2020 17:52
Bar plot with 0's value
# Source: https://plotly.com/r/bar-charts/
library(plotly)
Animals <- c("giraffes", "orangutans", "monkeys")
SF_Zoo <- c(20, 14, 0)
LA_Zoo <- c(12, 18, 29)
data <- data.frame(Animals, SF_Zoo, LA_Zoo)
fig <- plot_ly(data, x = ~Animals, y = ~SF_Zoo, type = 'bar', name = 'SF Zoo')
fig <- fig %>% add_trace(y = ~LA_Zoo, name = 'LA Zoo')
for(i in 1:21){
if(i == 1){
#if first year
y <- 350
x <- 0
} else {
# else increasing every year by 20%
y <- y * 1.2
}
x <- x + y
@RamiKrispin
RamiKrispin / missmech_from_archive.R
Created January 11, 2021 20:31
Install package from CRAN archive
install.packages("https://cran.r-project.org/src/contrib/Archive/MissMech/MissMech_1.0.2.tar.gz", repos=NULL, type="source")
@RamiKrispin
RamiKrispin / app.R
Last active January 28, 2021 04:48
An example for bookmark with navbarPage
# Source: https://shiny.rstudio.com/reference/shiny/0.14/bookmarkButton.html
# Changes - using navbarPage instead of tabsetPanel
ui <- function(request) {
fluidPage(
navbarPage(title = "Bookmark Multi Tabs Example",
id = "navbar",
position = "static-top",
theme = shinythemes::shinytheme("yeti"),
tabPanel("One",
@RamiKrispin
RamiKrispin / covid19_api.R
Created February 17, 2021 14:53
Pulling Israel Covid19 data from data.gov.il API
# Pulling Covid19 Isreal data
# Source - https://data.gov.il/dataset/covid-19/resource/d07c0771-01a8-43b2-96cc-c6154e7fa9bd
# Set the query's number of rows limit
limit <- 1000000
# Method 2
# Using httr to pull the data and jsonlite to parse the data
q <- httr::GET(