Skip to content

Instantly share code, notes, and snippets.

View AndreaCirilloAC's full-sized avatar

Andrea Cirillo AndreaCirilloAC

View GitHub Profile
@AndreaCirilloAC
AndreaCirilloAC / text_from_html.R
Created September 29, 2016 10:25
quick and dirty code to extraplate text from html file with custom tag
library(rio)
library(dplyr)
read_file = function(file_path) {
file_connection <- file(file_path, "r")
read_data <- c()
while ( TRUE ) {
@AndreaCirilloAC
AndreaCirilloAC / concistency_check_arithmetic.R
Created September 12, 2016 10:41
sample code on how to check serial number consistency through comparison of expected arithmetic series sum to actual sum
library(dplyr)
data <- data.frame(cod = c(rep("A",9),rep("B",10)),id =c(c(1,3,4,5,6,7,8,9,10),seq(1,10)))
data_complete <- filter(data,cod == "A")
min_step <- min (data_complete$id)
max_step <- max(data_complete$id)
expected_sum <- (1/2)*max(data$id)*(min_step+max_step)
actual_sum <- sum(data$id)
check <- expected_sum - actual_sum
@AndreaCirilloAC
AndreaCirilloAC / bike_sharing.R
Created August 22, 2016 07:42
bike sharing in washington by season
library(rio)
library(dplyr)
library(ggplot2)
# data from: https://www.kaggle.com/c/bike-sharing-demand/data
rides_stat <- import ("train.csv")
rides_stat %>%
group_by(season) %>%
summarise(total_rides = sum(count),mean_temp = mean(temp)) %>%
ggplot(aes(x=season,y=total_rides, fill = mean_temp)) +
geom_bar(stat='identity')+
@AndreaCirilloAC
AndreaCirilloAC / bernoulli_function.R
Last active August 10, 2016 12:22
a simple function to simulate geometric distribution for a given p of success and number of trials, producing a ggplot bar plot of the distribution
require(ggplot2)
#bernoulli
bernoulli_trial <- function(p_succ,n_trials){ # probability of success (1) and number of trials
p_insucc <- 1-p_succ # rpobability of failure
trials <<- c()
p_cumulative <<- c()
for(i in 1:n_trials){
trials <<- rbind(trials,i)
p_cumulative <<- rbind(p_cumulative,(((p_insucc)^(i -1))*p_succ)) # (p of success within n trials) = ((1-p)^n-1)*(p)
}
updateR(admin_password = "os_admin_user_password")
@AndreaCirilloAC
AndreaCirilloAC / dynamic_plot.R
Last active August 23, 2016 10:07
this code produce a semi-automated workflow to create and saw plots at a custom location with png format.
library(dplyr)
library(ggplot2)
create_file <- function(name){
path <- paste(getwd(),"/",name,".png",sep = '') %>%
file.path() %>% png(,width=960,height=480)
}
#this is the template: change the theme (and the name argument) to produce the other plots