byIndv4Intvl_ValueCalc: Calculates a single value that is a 'function' of the values...

byIndv4Intvl_ValueCalcR Documentation

Calculates a single value that is a function of the values of an individual for a response in a data.frame in long format over a specified time interval.

Description

Splits the values of a response into subsets corresponding individuals and applies a function that calculates a single value from each individual's observations during a specified time interval. It includes the ability to calculate the observation number that is closest to the calculated value of the function and the assocated values of a factor or numeric.

Usage

byIndv4Intvl_ValueCalc(data, response, 
                       individuals = "Snapshot.ID.Tag", times = "DAP", 
                       FUN = "max", which.obs = FALSE, which.values = NULL, 
                       addFUN2name = TRUE, sep.FUNname = ".", 
                       start.time=NULL, end.time=NULL, 
                       suffix.interval=NULL, sep.suffix.interval = ".", 
                       sep.levels=".", weights=NULL, na.rm=TRUE, ...)

Arguments

data

A data.frame containing the column from which the function is to be calculated.

response

A character giving the name of the column in data from which the values of FUN are to be calculated.

individuals

A character giving the name of the factor that defines the subsets of the data for which each subset corresponds to the response values for an individual (e.g. plant, pot, cart, plot or unit).

times

A character giving the name of the column in data containing the times at which the data was collected, either as a numeric, factor, or character. It will be used in calculating growth rates and, if a factor or character, the values should be numerics stored as characters.

FUN

A character giving the name of the function that calculates the value for each subset.

which.obs

A logical indicating whether or not to determine the observation number corresponding to the observed value that is closest to the value of the function, in addition to the value of the function itself. That is, FUN need not return an observed value of the reponse, e.g. quantile.

which.values

A character giving the name of the factor or numeric whose values are associated with the response values and whose value is to be returned for the observation number whose response value corresponds to the observed value closest to the value of the function. That is, FUN need not return an observed value of the reponse, e.g. quantile. In the case of multiple observed response values satisfying this condition, the value of the which.values vector for the first of these is returned.

addFUN2name

A logical that, if TRUE, indicates that the FUN name is to be added to the names of the columns in the data.frame returned by byIndv4Intvl_ValueCalc.

sep.FUNname

A character giving the character(s) to be used to separate the name of FUN from the response value in constructing the name for a new response. For no separator, set to "".

start.time

A numeric giving the times, in terms of levels of times.factor, that will give a single value for each Snapshot.ID.Tag and that will be taken as the observation at the start of the interval for which a value is to be calculated. If start.time is NULL, the interval will start with the first observation. In the case of multiple observed response values satisfying this condition, the first is returned.

end.time

A numeric giving the times, in terms of levels of times.factor, that will give a single value for each Snapshot.ID.Tag and that will be taken as the observation at the end of the interval for which a value is to be calculated. If end.time is NULL, the interval will end with the last observation.

suffix.interval

A character giving the suffix to be appended to response to form the name of the column containing the calculated values. If it is NULL then nothing will be appended.

sep.suffix.interval

A character giving the separator to use in appending suffix.inteval to a growth rate. For no separator, set to "".

sep.levels

A character giving the separator to use when the levels of individuals are combined. This is needed to avoid using a character that occurs in a factor to delimit levels when the levels of individuals are combined to identify subsets.

weights

A character giving the name of the column in data containing the weights to be supplied as w to FUN.

na.rm

A logical indicating whether NA values should be stripped before the calculation proceeds.

...

allows for arguments to be passed to FUN.

Value

A data.frame, with the same number of rows as there are individuals, containing a column for the individuals and a column with the values of the function for the individuals. It is also possible to determine observaton numbers or the values of another column in data for the response values that are closest to the FUN results, using either or both of which.obs and which.values. If which.obs is TRUE, a column with observation numbers is included in the data.frame. If which.values is set to the name of a factor or a numeric, a column containing the levels of that factor or the values of that numeric is included in the data.frame.

The name of the column with the values of the function will be result of concatenating the response, FUN and, if it is not NULL, suffix.interval, each separated by a full stop. If which.obs is TRUE, the column name for the obervations numbers will have .obs added after FUN into the column name for the function values; if which.values is specified, the column name for these values will have a full stop followed by which.values added after FUN into the column name for the function values.

Author(s)

Chris Brien

See Also

byIndv4Intvl_GRsAvg, byIndv4Intvl_GRsDiff, byIndv4Intvl_WaterUse, splitValueCalculate,
getTimesSubset

Examples

data(exampleData)
sPSA.max <- byIndv4Intvl_ValueCalc(data = longi.dat, 
                                   response = "sPSA", times = "DAP", 
                                   start.time = 31, end.time = 35, 
                                   suffix.interval = "31to35")
AGR.max.dat <- byIndv4Intvl_ValueCalc(data = longi.dat, 
                                      response = "sPSA", times = "DAP", 
                                      FUN="max", 
                                      start.time = 31, end.time = 35, 
                                      suffix.interval = "31to35",
                                      which.values = "DAP", 
                                      which.obs = TRUE)

growthPheno documentation built on Oct. 24, 2023, 5:08 p.m.