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(zoo) | |
browseURL("https://itsalocke.com/blog/understanding-rolling-calculations-in-r/") | |
dat <- read.csv("https://raw.githubusercontent.com/juanchiem/agro_data/master/hourly_weather.csv", | |
header = TRUE, sep = ";") | |
dat %>% | |
slice(1:48) %>% | |
mutate(tmean_12 = rollapply(temp, | |
width = 12, mean, | |
align = "right", |
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("geometry") | |
data.frame(trap_degree = c(0,0,90,90), | |
distance_m = c(100, 200, 100, 200))%>% | |
mutate(data.frame(pol2cart(theta = trap_degree, r = distance_m))) %>% | |
ggplot()+ | |
aes(x=y, y=x)+ | |
geom_point() + | |
geom_text(aes(label=paste0(trap_degree,",", distance_m), vjust=1))+ |
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(purrr) | |
library(tidyverse) | |
newdata=data.frame(Sepal.Length=seq(4, 8, by=.5)) | |
# newdata$Sepal.Length | |
fitted_models <- iris %>% | |
nest(data = -Species) %>% | |
mutate(fit = map(data, ~ lm(Petal.Length ~ Sepal.Length + I(Sepal.Length^2), data = .x)), | |
# fitted = map(fit, "fitted.values"), | |
predicted_Petal.Length= map(fit, ~ predict(.x, newdata = newdata)) |
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
```{r} | |
pacman::p_load( | |
tidyverse, | |
skimr, janitor,# exploracion de los datos | |
lme4, gamlss, # modelado | |
ggResidpanel, # diagnostico | |
DHARMa, | |
performance, # evaluar performance de los modelos | |
emmeans, # medias estimadas por el modelo |
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
# the first argument gives expansion equal to its multiplication by limit range; | |
ggplot(mpg, aes(displ, hwy)) + | |
geom_point() + | |
scale_x_continuous(limits = c(1, 7), expand = c(.1, 0)) | |
# right position will be 7 + (7-1) * .1 = 7.6 | |
# the second gives the absolute expansion added to both end of the axis: | |
ggplot(mpg, aes(displ, hwy)) + | |
geom_point() + | |
scale_x_continuous(limits = c(1, 7), expand = c(0, 1)) |
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
dat <- tibble( | |
x_1 = runif(10), | |
x_2 = runif(10), | |
x_3 = runif(10) | |
) | |
dat |> | |
mutate( | |
across( | |
.cols = everything(), | |
.fns = rank, |
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
# devtools::install_github('byzheng/weaana') | |
library(weaana) | |
file <- system.file("extdata/WeatherRecordsDemo1.met", package = "weaana") | |
# Read weather file - met file | |
met <- readWeatherRecords(file) | |
x_temp <- c(0, 26, 34) | |
y_temp <- c(0, 26, 0) |
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
How to use R with SQLlite | |
================ | |
This is a walkthrough of how you can use SQLite with R from my twitter | |
[@neilgcurrie](https://twitter.com/neilgcurrie). | |
Often in R we read in files of mixed formats. This gets messy fast and | |
when the data is too big R will lag or fall over. Enter the database. | |
SQLite is software used to interact with databases and is one of the | |
most popular engines around. We can work with SQLite directly from R. |
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(lubridate) | |
u <- "https://raw.githubusercontent.com/juanchiem/agro_data/master/weather_africa.csv" | |
sol <- rio::import(u) | |
sol %>% glimpse | |
sol %>% | |
mutate(date1= update(mdy(date), year = 1800)) %>% |
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
AntroSO42<-read.csv("antroSO42-.csv", header = TRUE) | |
Bp <- AntroSO42[ ,(2:4), ] | |
library(tidyverse) | |
Bp %>% | |
gather(value, variable, -Class) %>% | |
ggplot(aes(Class, | |
variable)) + | |
geom_boxplot() + | |
facet_wrap( ~ value) + |