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
# GAM model with a local smoother | |
library(tidyverse) | |
set.seed(2) | |
elapsed <- arima.sim(model = list(order = c(0, 1, 0)), n=200) + 20 | |
elapsed <- pmax(elapsed, 1) | |
data <- tibble( | |
x = 1:201, | |
elapsed = elapsed | |
) | |
plot(data) |
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
# Single grouping in base R: Multiple functions | |
library(dplyr, warn.conflicts = FALSE) | |
expected_output <- mtcars %>% | |
group_by(cyl) %>% | |
summarise(mean = mean(disp), n = n()) %>% | |
as.data.frame() | |
expected_output | |
by <- c("cyl") |
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
<VRTDataset rasterXSize="10" rasterYSize="10"> | |
<SRS dataAxisToSRSAxisMapping="2,1">GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]</SRS> | |
<GeoTransform> 0.0000000000000000e+00, 1.0000000000000000e+00, 0.0000000000000000e+00, 9.0000000000000000e+01, 0.0000000000000000e+00, -1.8000000000000000e+01</GeoTransform> | |
<VRTRasterBand dataType="Float32" band="1"> | |
<NoDataValue>nan</NoDataValue> | |
<ColorInterp>Gray</ColorInterp> | |
<ComplexSource> | |
<SourceFilename relativeToVRT="0">rasters/raster.tif</SourceFilename> | |
<SourceBand>1</SourceBand> | |
<SourceProperties RasterXSize="10" RasterYSize="10" DataType="Float32" BlockXSize="10" BlockYSize="10" /> |
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
# combine_multylayered_raster_vtr.R: Combine multilayered_raster vtr using terra package | |
library(terra) | |
test <- TRUE | |
test_create_vrt_from_multilayers <- function() { | |
raster_objects <- create_multiplayered_rasters() | |
print(class(raster_objects[[1]]) == "SpatRaster") | |
print(class(raster_objects[[2]]) == "SpatRaster") | |
out <- create_vrt_from_multilayers(raster_objects) | |
print(out) |
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) | |
economics_raw <- read_csv("https://gist.githubusercontent.com/jrosell/cf35e54a70914a3b23946c0a0d3a2cee/raw/47e52b910ecb23c3c7a8c549c9fd277797bd9970/economics_long.csv") | |
print(economics_raw, n = 5) | |
glimpse(economics_raw) | |
economics_raw %>% | |
glimpse(x = .) |
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
date | variable | value | value01 | |
---|---|---|---|---|
1967-07-01 | pce | 506.7 | 0 | |
1967-08-01 | pce | 509.8 | 2.652497197765077e-4 | |
1967-09-01 | pce | 515.6 | 7.615233890357775e-4 | |
1967-10-01 | pce | 512.2 | 4.7060434153896666e-4 | |
1967-11-01 | pce | 517.4 | 9.155393553576157e-4 | |
1967-12-01 | pce | 525.1 | 0.001574385433512166 | |
1968-01-01 | pce | 530.9 | 0.002070659102771431 | |
1968-02-01 | pce | 533.6 | 0.002301683052254198 | |
1968-03-01 | pce | 544.3 | 0.003217222407611809 |
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
# install.packages("pak") | |
stopifnot( | |
'{pak} no está instalado. Por favor, ejecuta install.packages("pak") en la consola y vuelve a intentarlo.' = | |
sum("pak" == row.names(installed.packages())) == 1 | |
) | |
instalar <- setdiff( | |
c("ggplot2", "dplyr", "tidyr", "readr", "purrr", "tibble", "stringr", "forcats", "lubridate", "magrittr", "tidyverse"), | |
rownames(installed.packages()) | |
) |
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
# Hasta 12450 euros: 19 % | |
# De 12.450 euros hasta 20.200 euros: 24 % | |
# De 20.200 euros hasta 35.200 euros: 30 % | |
# De 35.200 euros hasta 60.000 euros: 37 % | |
# De 60.000 euros hasta300.000 euros: 45 % | |
# Más de 300.000 euros: 47 % | |
library(tidyverse) | |
library(patchwork) |
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
// Create my_date_month custom field from existing date field my_date | |
MONTH(my_date) | |
// Create my_date_YYYYMM ucstom field from existing numeric field my_date and my_date_month | |
CASE | |
WHEN my_date_month=1 THEN CONCAT(YEAR(my_date),'01') | |
WHEN my_date_month=2 THEN CONCAT(YEAR(my_date),'02') | |
WHEN my_date_month=3 THEN CONCAT(YEAR(my_date),'03') | |
WHEN my_date_month=4 THEN CONCAT(YEAR(my_date),'04') | |
WHEN my_date_month=5 THEN CONCAT(YEAR(my_date),'05') |
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
// View item: It should be executed when the product detail is shown. | |
dataLayer.push({ ecommerce: null }); | |
dataLayer.push({ | |
event: "view_item", | |
ecommerce: { | |
currency: "USD", | |
value: 7.77, | |
items: [ | |
{ | |
item_id: "SKU_12345", |