-
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
1 parent
6273471
commit 3905f72
Showing
11 changed files
with
128 additions
and
157 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
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,47 @@ | ||
#' Data Dimensions | ||
#' | ||
#' Show the data dimensions of a table. | ||
#' | ||
#' @param x a data frame where the first columns are dimension variables and the | ||
#' last column is a measurement variable. | ||
#' @param reduce is whether to omit single-level dimensions. | ||
#' | ||
#' @details | ||
#' Dimension variables can include year, age, region, fleet, survey, or the | ||
#' like, generally an integer or string. The measurement variable can be catch, | ||
#' fishing mortality, maturity, weight, or the like, often a decimal. | ||
#' | ||
#' \code{x} can also be an FLR table in \code{FLQuant} format. | ||
#' | ||
#' @return Named vector showing the dimension names and number of levels. | ||
#' | ||
#' @seealso | ||
#' \code{\link{unique}} is the base function to extract the levels of a | ||
#' dimension variable. | ||
#' | ||
#' \code{\link{TAF-package}} gives an overview of the package. | ||
#' | ||
#' @examples | ||
#' # Long table format, 8 years and 4 ages | ||
#' ddim(catage.long) | ||
#' | ||
#' # Some base R datasets | ||
#' ddim(esoph[-5]) | ||
#' ddim(rev(warpbreaks)) | ||
#' ddim(rev(ToothGrowth)) | ||
#' | ||
#' @importFrom methods is | ||
#' @importFrom stats setNames | ||
#' | ||
#' @export | ||
|
||
ddim <- function(x, reduce=FALSE) | ||
{ | ||
out <- if(is(x, "FLQuant")) | ||
setNames(dim(x), names(dimnames(x))) | ||
else | ||
sapply(x, function(col) length(unique(col)))[-ncol(x)] | ||
if(reduce) | ||
out <- out[out != 1] | ||
out | ||
} |
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
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.
This file was deleted.
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.
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