Add a total radius-at-capture variable to a data.frame that contains one-fish-per-line (i.e., “wide” format) increments data.

addRadCap(df, in.pre = NULL, in.var = NULL, var.name = "radcap")

Arguments

df

A data.frame that contains the growth increment data in one-fish-per-line (i.e., “wide”) format.

in.pre

A string that represents the common part of the increment variable names. See details.

in.var

A vector of variables in df that do not change. See details.

var.name

A string that indicates the name for the new total radius-at-capture variable in the new data.frame. Defaults to “radcap”.

Value

A data.frame of increments in one-fish-per-line (i.e., “wide”) format with the total radius-at-capture appended in a variable named as given in var.name.

Details

The columns that contain the original increment data can specified in a variety of ways. First, if all columns begin with the same prefix (and no other columns contain that prefix), then the prefix string may be given to in.pre=. Second, a sequence of column numbers may be given to in.var= with #:# (if the columns are contiguous) or as a vector (if the columns are not contiguous). Third, a vector of column names may be given to in.var=. Note that one, but not both, of in.var= or in.pre= must be specified by the user.

Note that the computed total radius-at-capture will only be the actual total radius-at-capture if all growth, including “plus-growth” in the current season, is recorded in the input data frame.

See also

See gConvert for related functionality.

Author

Derek H. Ogle, DerekOgle51@gmail.com

Examples

## Get data with radial measurements
data(SMBassWB,package="FSA")
head(SMBassWB)
#>   species lake gear yearcap fish agecap lencap    anu1 anu2 anu3 anu4 anu5 anu6
#> 1     SMB   WB    E    1988    5      1     71 1.90606   NA   NA   NA   NA   NA
#> 2     SMB   WB    E    1988    3      1     64 1.87707   NA   NA   NA   NA   NA
#> 3     SMB   WB    E    1988    2      1     57 1.09227   NA   NA   NA   NA   NA
#> 4     SMB   WB    E    1988    4      1     68 1.31848   NA   NA   NA   NA   NA
#> 5     SMB   WB    E    1988    6      1     72 1.59283   NA   NA   NA   NA   NA
#> 6     SMB   WB    E    1988    7      1     80 1.91602   NA   NA   NA   NA   NA
#>   anu7 anu8 anu9 anu10 anu11 anu12  radcap
#> 1   NA   NA   NA    NA    NA    NA 1.90606
#> 2   NA   NA   NA    NA    NA    NA 1.87707
#> 3   NA   NA   NA    NA    NA    NA 1.09736
#> 4   NA   NA   NA    NA    NA    NA 1.33108
#> 5   NA   NA   NA    NA    NA    NA 1.59283
#> 6   NA   NA   NA    NA    NA    NA 1.91602

## convert radial measurements to increments
SMBi1 <- gConvert(SMBassWB,in.pre="anu",out.type="inc")
head(SMBi1)
#>   species lake gear yearcap fish agecap lencap  radcap    inc1 inc2 inc3 inc4
#> 1     SMB   WB    E    1988    5      1     71 1.90606 1.90606   NA   NA   NA
#> 2     SMB   WB    E    1988    3      1     64 1.87707 1.87707   NA   NA   NA
#> 3     SMB   WB    E    1988    2      1     57 1.09736 1.09227   NA   NA   NA
#> 4     SMB   WB    E    1988    4      1     68 1.33108 1.31848   NA   NA   NA
#> 5     SMB   WB    E    1988    6      1     72 1.59283 1.59283   NA   NA   NA
#> 6     SMB   WB    E    1988    7      1     80 1.91602 1.91602   NA   NA   NA
#>   inc5 inc6 inc7 inc8 inc9 inc10 inc11 inc12
#> 1   NA   NA   NA   NA   NA    NA    NA    NA
#> 2   NA   NA   NA   NA   NA    NA    NA    NA
#> 3   NA   NA   NA   NA   NA    NA    NA    NA
#> 4   NA   NA   NA   NA   NA    NA    NA    NA
#> 5   NA   NA   NA   NA   NA    NA    NA    NA
#> 6   NA   NA   NA   NA   NA    NA    NA    NA

## add the radius-at-capture measurement
SMBi1a <- addRadCap(SMBi1,in.pre="inc",var.name="radcap2")
head(SMBi1a)
#>   species lake gear yearcap fish agecap lencap  radcap    inc1 inc2 inc3 inc4
#> 1     SMB   WB    E    1988    5      1     71 1.90606 1.90606   NA   NA   NA
#> 2     SMB   WB    E    1988    3      1     64 1.87707 1.87707   NA   NA   NA
#> 3     SMB   WB    E    1988    2      1     57 1.09736 1.09227   NA   NA   NA
#> 4     SMB   WB    E    1988    4      1     68 1.33108 1.31848   NA   NA   NA
#> 5     SMB   WB    E    1988    6      1     72 1.59283 1.59283   NA   NA   NA
#> 6     SMB   WB    E    1988    7      1     80 1.91602 1.91602   NA   NA   NA
#>   inc5 inc6 inc7 inc8 inc9 inc10 inc11 inc12 radcap2
#> 1   NA   NA   NA   NA   NA    NA    NA    NA 1.90606
#> 2   NA   NA   NA   NA   NA    NA    NA    NA 1.87707
#> 3   NA   NA   NA   NA   NA    NA    NA    NA 1.09227
#> 4   NA   NA   NA   NA   NA    NA    NA    NA 1.31848
#> 5   NA   NA   NA   NA   NA    NA    NA    NA 1.59283
#> 6   NA   NA   NA   NA   NA    NA    NA    NA 1.91602