Description Usage Arguments Details See Also Examples
abundance()
counts the number of rows in a dataset, optionally by groups
created with dplyr::group_by()
(similar to dplyr::n()
). It warns if it
detects duplicated values of treeid.
basal_area()
sums the basal area of
all stems in a dataset, optionally by groups created with group_by()
. It
warns if it detects duplicated values of stemid. It does not convert units
(but see examples).
Both abundance()
and basal_area()
warn if they detect
multiple censusid and multiple plots.
1 2 3 |
data |
A dataframe. |
You may want to calculate the abundance or basal area for a specific subset
of data (e.g. "alive" stems or stems which dbh
is within some range).
Subsetting data is not the job of these functions. Instead see
base::subset()
, dplyr::filter()
, or [
.
dplyr::n()
, dplyr::group_by()
.
Other functions for abundance and basal area:
abundance_byyr()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | library(fgeo.tool)
# abundance() -------------------------------------------------------------
abundance(data.frame(1))
# One stem per tree
tree <- tribble(
~TreeID, ~StemID, ~DBH,
"1", "1.1", 11,
"2", "2.1", 21
)
abundance(tree)
# One tree with multiple stems
stem <- tribble(
~TreeID, ~StemID, ~DBH,
"1", "1.1", 11,
"1", "1.2", 12
)
abundance(stem)
# Skip R CMD check for speed
# Similar but more realistic
assert_is_installed("fgeo.x")
stem <- fgeo.x::download_data("luquillo_stem5_random")
abundance(stem)
abundance(pick_main_stem(stem))
vft <- tribble(
~PlotName, ~CensusID, ~TreeID, ~StemID, ~DBH,
"p", 1, "1", "1.1", 10,
"q", 2, "1", "1.1", 10
)
# * Warns if it detects multiple values of censusid or plotname
# * Also warns if it detects duplicated values of treeid
abundance(vft)
# If trees have buttressess, the data may have multiple stems per treeid or
# multiple measures per stemid.
vft2 <- tribble(
~CensusID, ~TreeID, ~StemID, ~DBH, ~HOM,
1, "1", "1.1", 88, 130,
1, "1", "1.1", 10, 160,
1, "2", "2.1", 20, 130,
1, "2", "2.2", 30, 130,
)
# You should count only the main stem of each tree
(main_stem <- pick_main_stem(vft2))
abundance(main_stem)
vft3 <- tribble(
~CensusID, ~TreeID, ~StemID, ~DBH, ~HOM,
1, "1", "1.1", 20, 130,
1, "1", "1.2", 10, 160, # Main stem
2, "1", "1.1", 12, 130,
2, "1", "1.2", 22, 130 # Main stem
)
# You can compute by groups
by_census <- group_by(vft3, CensusID)
(main_stems_by_census <- pick_main_stem(by_census))
abundance(main_stems_by_census)
# basal_area() ------------------------------------------------------------
# Data must have a column named dbh (case insensitive)
basal_area(data.frame(dbh = 1))
# * Warns if it detects multiple values of censusid or plotname
# * Also warns if it detects duplicated values of stemid
basal_area(vft)
# First you may pick the main stemid of each stem
(main_stemids <- pick_main_stemid(vft2))
basal_area(main_stemids)
# You can compute by groups
basal_area(by_census)
# Skip R CMD check for speed
measurements_is_installed <- requireNamespace("measurements", quietly = TRUE)
if (measurements_is_installed) {
library(measurements)
# Convert units
ba <- basal_area(by_census)
ba$basal_area_he <- conv_unit(
ba$basal_area,
from = "mm2",
to = "hectare"
)
ba
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.