-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Arni Magnusson
committed
Apr 27, 2017
1 parent
052e2b5
commit fd31ce3
Showing
9 changed files
with
185 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: icesTAF | ||
Version: 1.0-0 | ||
Date: 2017-02-17 | ||
Version: 1.1-0 | ||
Date: 2017-04-27 | ||
Title: Functions to Support the ICES Transparent Assessment Framework | ||
Authors@R: c(person("Arni", "Magnusson", role=c("aut","cre"), email="[email protected]"), | ||
person("Colin", "Millar", role="aut")) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#' Convert FLR table to TAF format | ||
#' | ||
#' Convert a simple crosstab table from FLR format to TAF format. | ||
#' | ||
#' @param x a table of class \code{FLQuant}. | ||
#' @param na a value that should be converted to NA. | ||
#' @param year whether the year should be stored in the first column, instead of | ||
#' row names. | ||
#' | ||
#' @note | ||
#' FLR uses the \code{FLQuant} class to store tables as 6-dimensional arrays, | ||
#' while TAF crosstabs are stored as data frames with a year column. | ||
#' | ||
#' @seealso | ||
#' \code{\link{as.data.frame}} is a method provided by the \pkg{FLCore} package | ||
#' to convert \code{FLQuant} tables to a 7-column long format. | ||
#' | ||
#' \code{\link{taf2long}} converts TAF tables to long format. | ||
#' | ||
#' \code{\link{icesTAF-package}} gives an overview of the package. | ||
#' | ||
#' @examples | ||
#' x <- array(round(runif(70)/3, 1), dim=c(7,10,1,1,1,1)) | ||
#' dimnames(x) <- list(age=2:8, year=1991:2000, | ||
#' unit="unique", season="all", area="unique", iter=1) | ||
#' flr2taf(x) | ||
#' flr2taf(x, na=0, year=FALSE) | ||
#' | ||
#' @export | ||
|
||
flr2taf <- function(x, na=NULL, year=TRUE) | ||
{ | ||
y <- as.data.frame(t(drop(unclass(x)))) | ||
if(year) | ||
{ | ||
y <- cbind(Year=as.integer(row.names(y)), y) | ||
row.names(y) <- NULL | ||
} | ||
if(!is.null(na)) | ||
{ | ||
y[y==na] <- NA | ||
} | ||
y | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#' Convert TAF table to long format | ||
#' | ||
#' Convert a table from TAF crosstab format to a 3-column long format. | ||
#' | ||
#' @param x a data frame containing crosstab data. | ||
#' @param names a vector of three column names for the resulting data frame. | ||
#' @param year whether the input table has year in the first column, instead of | ||
#' row names. | ||
#' | ||
#' @note | ||
#' TAF stores crosstab tables as data frames with a year column, as seen in | ||
#' stock assessment reports. The long format is practical for analysis and | ||
#' producing plots. | ||
#' | ||
#' @seealso | ||
#' \code{\link{flr2taf}} converts tables from FLR to TAF format. | ||
#' | ||
#' \code{\link{icesTAF-package}} gives an overview of the package. | ||
#' | ||
#' @examples | ||
#' fish <- matrix(round(runif(30),3), 5) | ||
#' fish <- data.frame(Year=2001:2005, fish, check.names=FALSE) | ||
#' taf2long(fish) | ||
#' | ||
#' alt <- fish[-1] | ||
#' row.names(alt) <- fish$Year | ||
#' taf2long(alt, names=c("Year","Age","Weight"), year=FALSE) | ||
#' | ||
#' @export | ||
|
||
taf2long <- function(x, names=c("Year","Age","Value"), year=TRUE) | ||
{ | ||
if(year) | ||
{ | ||
row.names(x) <- x[[1]] | ||
x <- x[-1] | ||
} | ||
y <- as.data.frame(as.table(as.matrix(x))) | ||
names(y) <- names | ||
y | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.