Skip to content

Instantly share code, notes, and snippets.

@nataliamd11
nataliamd11 / m_mm_ac
Created July 31, 2018 00:20
head of m_mm_ac and m_t_mean
# > head(m_mm_ac)
# month.order year accumulated.value
# 1 10 2007 0.6
# 2 11 2007 26.7
# 3 12 2007 68.3
# > head(m_t_mean)
# month.order year mean.value
# 1 10 2007 22.48750
# 2 11 2007 21.04500
# 3 12 2007 23.29516
@nataliamd11
nataliamd11 / calera_organized
Created July 30, 2018 23:09
result of OrganizeDateColumns
calera_organized <- OrganizeDateColumns(data.x = calera_raw, ncol.date = 1, orders = "mdyHMS", ncol.day = NULL, ncol.month = NULL, ncol.year = NULL)
head(calera_organized)
#
# > head(calera_organized)
# fecha mm temp humedad day month year
# 1 2018-04-27 0 22.8 49.8 27 4 2018
# 2 2018-04-27 0 24.0 47.9 27 4 2018
# 3 2018-04-27 0 26.4 45.5 27 4 2018
# 4 2018-04-27 0 25.9 49.7 27 4 2018
# 5 2018-04-27 0 26.0 56.7 27 4 2018
@nataliamd11
nataliamd11 / HourlyToDaily
Created July 30, 2018 22:53
HourlyToDaily-function that obtain daily data from hourly data
HourlyToDaily <- function(data.x, ncol.obs, ncol.date, na.presence = TRUE, value = "mean") {
#
if (!any(value == c("mean", "accumulated"))) {
stop(" value must to be 'mean' or 'accumulated'")
}
# Calculate the mean of the variable of interest
first.year <- min(data.x$year, na.rm = na.presence)
last.year <- max(data.x$year, na.rm = na.presence)
x.daily.per.years <- list()
date.tot <- list()
@nataliamd11
nataliamd11 / calera_raw
Created July 30, 2018 20:15
read_data_from_la_calera.R
# First we read the .csv with the data from La Calera
#
calera_raw <- read.csv(".../meteorologicos_la_calera.csv")
head(calera_raw)
#
#> head(calera)
# fecha mm temp humedad
# 1 04/27/2018 17:00:00 0 22.8 49.8
# 2 04/27/2018 16:00:00 0 24.0 47.9
# 3 04/27/2018 15:00:00 0 26.4 45.5
@nataliamd11
nataliamd11 / OrganizeDateColumns.R
Created July 30, 2018 20:10
Function that creates day, month and year columns.
# Function that creates day, month and year columns.
#
OrganizeDateColumns <- function(data.x, ncol.date = 1, orders = "mdyHMS", ncol.day = NULL, ncol.month = NULL, ncol.year = NULL) {
#
require(lubridate)
#
# Organizes dates's columns using lubridate
# If columns with days, months or years are NULL, creates these columns with a
# function inside the function
#