g.reshape {FSA}R Documentation

Reshapes a one-fish-per-line data frame to a one-measurement-per-line data frame.

Description

Converts growth data from the one-fish-per-line format to the one-measurement-per-line format. One-fish-per-line format is a common form of collecting or storing growth data. One-measurement-per-line format is required for many statistical analyses.

Usage

g.reshape(df,in.pre,id.var,var.name="age",val.name=in.pre,
          last.plus=NULL,na.rm=TRUE)

Arguments

df A data frame containing the growth measurement data in one-fish-per-line format. A specific format is required – see details.
in.pre A string that represents the common part of the measurement variable names. See details.
id.var A vector of variables in df that do not change. See details.
var.name A string indicating the name in the reshaped data frame that represents the level of the measurement variables in the original data frame.
val.name A string indicating the name in the reshaped data frame that represents the measurements in the orginal data frame.
last.plus A string that if non-null indicates that the last measurement represents “plus growth” and not an actual increment. If “plus growth” is recorded then this string should indicate the name of the variable that contains the age of the fish at capture.
na.rm A logical indicating whether NA values in the measurement variables should be removed after reshaping.

Details

This function does NOT convert the data from radial to incremental or incremental to radial measurements (see g.convert).

The input data frame in df must have the following specific formats. First, the measurements of annular increments or radii must be in one-fish-per-line format (see g.convert for converting from one-fish-per-line format). The measurements must be contained in columns that are named with a common prefix (e.g., “anu”, “inc”, or “rad”) followed by a number that represents the age of the fish to which that measurement belongs. This prefix must be the same for all columns containing measurements and must not be found in any other variable (as a prefix or not). For example, the first annular measurement should be in a variable named “anu1”, the second annular measurement in “anu2”, and so on. The name of the prefix should be included in the in.pre= argument. This prefix is used to identify the measurment.var argument to send to the melt function in the reshape package (see more below). In addition, this prefix is removed from the names in such a way that the age at the time of the measurement can be returned in the reshaped output data frame.

If id.var is left blank then the vector of variables that will not be changed upon the reshaping will consist of all variables that do NOT contain the in.pre prefix.

The name of the variable in the reshaped output data frame containing the measurements will be called the same as id.pre by default. This can be changed by including a new name as the string in the val.name argument.

This function follows the general format for reshaping with the melt function in reshape.

Value

Returns a data frame in one-measurement-per-line format. See details.

Author(s)

Derek H. Ogle, dogle@northland.edu

See Also

g.convert, melt in reshape

Examples

data(SMBassWB)
head(SMBassWB)

# convert radial measurements to increments
SMBi1 <- g.convert(SMBassWB,in.pre="anu",type="inc")
head(SMBi1)

SMBi1a <- g.reshape(SMBi1,in.pre="inc")
head(SMBi1a)

# same as above but assume that last increment (in agecap variable) is plus-growth
SMBi2a <- g.reshape(SMBi1,in.pre="inc",last.plus="agecap")
head(SMBi2a)

[Package FSA version 0.0-13 Index]