Learn R Programming

stxplore (version 0.1.0)

temporal_means: Computes temporal empirical means using a dataframe or a stars object.

Description

This function computes temporal empirical means averaged per time unit. This function can take either a stars object or a dataframe. Input arguments differ for each case. The function autoplot plots the output.

Usage

temporal_means(x, ...)

# S3 method for data.frame temporal_means(x, t_col, z_col, id_col, ...)

# S3 method for stars temporal_means(x, ...)

# S3 method for temporalmeans autoplot( object, ylab = "Value", xlab = "Time", legend_title = "", title = "Temporal Empirical Means", ... )

Value

An object of class temporalmeans containing the averages and the original data in two dataframes.

Arguments

x

A stars object or a dataframe. Arguments differ according to the input type.

...

Other arguments currently ignored.

t_col

For dataframes: the time column. Time must be a set of discrete integer values.

z_col

For dataframes: the The quantity of interest that will be plotted. Eg. temperature.

id_col

The column of the location id.

object

For autoplot: the output of the function `temporal_means'.

ylab

The y label.

xlab

The x label.

legend_title

For autoplot: the title for the legend.

title

The graph title.

Examples

Run this code
# dataframe example
data(NOAA_df_1990)
library(dplyr)
Tmax <- filter(NOAA_df_1990,                      # subset the data
              proc == "Tmax" &                   # extract max temperature
                month %in% 5:9 &                 # May to July
                year == 1993)                    # year 1993
Tmax$t <- Tmax$julian - min(Tmax$julian) + 1      # create a new time variable starting at 1
tem <- temporal_means(Tmax,
       t_col = 'date',
       z_col = 'z',
       id_col = 'id')
autoplot(tem)

# stars example
library(stars)
library(dplyr)
library(units)
# Example
prec_file = system.file("nc/test_stageiv_xyt.nc", package = "stars")
prec <- read_ncdf(prec_file)
temporal_means(prec)

Run the code above in your browser using DataLab