View source: R/summarise_field_2d.R
summarise_field_2d | R Documentation |
This function produces summary statistics of the variation in environmental conditions across a mesh on a given day. These statistics can be computed either separately for each specified hour, if the inputted array has a row corresponding to those hours, across all hours, or for a single hour if the inputted array contains a single row.
summarise_field_2d( data, row_specific = TRUE, funs = list(mean = mean, min = min, max = max) )
data |
An n x m matrix, in which n are the hours and m are the mesh cells across which you want to calculate summary statistics. |
row_specific |
A logical input specifying whether summary statistics should be calculated for every row (i.e. hour) in the matrix ( |
funs |
A named list of functions that you want to evaluate across all mesh cells for each of the specified hours. Each element in the list should be named with a name that corresponds to the function applied (see Examples). |
A dataframe with a row for each hour across which statistics were calculated and a column for each summary statistic. The column names correspond to the names provided in the funs
argument.
Edward Lavender
#### Load in WeStCOMS data and process data as required into a 2-dimensional field: path <- system.file("WeStCOMS_files/temp", package = "fvcom.tbx", mustWork = TRUE) # Define the path to the temperature file for 2016-03-01: pathname <- file.path(path, "160301.mat") # Read in the file using the R.matlab package: sample <- R.matlab::readMat(pathname) # Extract the model output (i.e. the 3-dimensional array) from the list using $data sample <- sample$data # Examine the structure of the array: str(sample) # For a 3-dimensional variable, define a specific layer across which to calculate summary statistics sample <- sample[, 1, ] str(sample) #### 1) Calculate row- (hour-) specific summary statistics across all mesh cells: # We have a 2 x 802 matrix; rows 1, 2, correspond to hours 1 and 2 in this case # ... so to calculate summary statistics across all mesh cells for each hour # ... apply the summarise2sfields as follows: ls <- summarise_field_2d(data = sample, row_specific = TRUE, funs = list(mean = mean, min = min, max = max, sd = stats::sd) ) # Examine outputs: ls #### 2) Calculate summary statistics across all rows (hours) and mesh cells: ls <- summarise_field_2d(data = sample, row_specific = FALSE, funs = list(mean = mean, min = min, max = max, sd = stats::sd) ) ls
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.