Skip to content

Instantly share code, notes, and snippets.

View renato04's full-sized avatar

Renato Ramos Nascimento renato04

  • Globant
  • São Paulo - Brazil
View GitHub Profile
@renato04
renato04 / create_file_example.R
Created June 5, 2019 23:25
How to download a write a file using R?
download = function(f){
if(!file.exists('data')){
dir.create('data')
}
file.local = file.path('./data', basename(f))
if(!file.exists(file.local)){
download.file(url = f, destfile = file.local , mode='wb')
}
@renato04
renato04 / random_samples.R
Created May 23, 2019 01:35
Random Samples in R
# Generates random numbers uniformly
histogram(runif(1:100000))
# Probabily of one numbe given a unifom random numbers
dunif(x= 8, min= 1, max=11)
# Samples
set.seed(1)
amostra = c("T","R","I", "A", "N", "G", "U", "L", "O")
sample(x = amostra, replace = FALSE)
@renato04
renato04 / matrix_operations.R
Created May 23, 2019 00:52
R Matrix operations
# Vector operations
a = c(333135, 19890804, 894, 478618, 2112)
b = a * 2
c = b / 3
d = c + a^2
e = sqrt(d)
# Reverse matrix
ai = rev(a)
@renato04
renato04 / high_order_functions_samples.py
Created May 17, 2019 13:21
Python High order function samples
# Composistion
def f(x):
return x + 2
def g(h, x):
return h(x) * 2
print(g(f, 42))
@renato04
renato04 / black_friday_r.R
Last active May 9, 2019 16:38
Calculate Next Black Friday Day R
install.packages('lubridate')
library(lubridate)
nextBlackFriday = function(year){
first_november = ymd(paste(year,"1101"))
day_of_week = wday(first_november, label = TRUE)
shift = ifelse(as.numeric(day_of_week) < 6, 0, 7)
next_friday = first_november + days(6 - as.numeric(day_of_week) + shift)
# Create a sequence
my_seq = seq(from = 1, by = 5, length.out = 30)
# Crete a sequence with the another list size
along = seq_along(my_seq)
@renato04
renato04 / r_special_values.R
Created May 8, 2019 23:34
R Special Values
# Special Values
na = NA
nan = NaN
infinity = Inf
less_inifinity = -Inf
null = NULL
my_vector = c(na, nan, infinity, less_inifinity, null)
@renato04
renato04 / data_strcutures_samples.R
Last active April 25, 2019 01:50
R - Data Structures Samples
vet_logical = c(T, T, F, F)
vet_int = 11:14
vet_numeric = c(1.0, 2.0, 3.0, 4.0)
vet_text = letters[1:4]
vet_imaginary = c((1 + 1i), (1 + 1i), (1 + 1i), (1 + 1i))
my_list = list(vet_logico, vet_int, vet_numerico, vet_texto, vet_imaginario)
my_matrix = matrix(seq(from=2, by=2, length.out = 16), nrow = 4)
@renato04
renato04 / memory_to_file.R
Created April 25, 2019 01:41
R - Memory to File
a = b = c = d = e = f = g = h = i = j = pi
save.image(choose.files())
@renato04
renato04 / app.js
Last active August 29, 2015 14:03 — forked from jgoux/app.js
angular.module('myApp', ['ionic', 'myApp.services', 'myApp.controllers'])
.run(function(DB) {
DB.init();
});