• 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.

abundance(data)

basal_area(data)

Arguments

data

A dataframe. basal_area() requires a column named dbh (case insensitive).

Details

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 [.

See also

dplyr::n(), dplyr::group_by().

Other functions for abundance and basal area: abundance_byyr()

Examples

#> #> Attaching package: ‘fgeo.tool’
#> The following object is masked from ‘package:stats’: #> #> filter
# abundance() ------------------------------------------------------------- abundance(data.frame(1))
#> # A tibble: 1 x 1 #> n #> <int> #> 1 1
# One stem per tree tree <- tribble( ~TreeID, ~StemID, ~DBH, "1", "1.1", 11, "2", "2.1", 21 ) abundance(tree)
#> # A tibble: 1 x 1 #> n #> <int> #> 1 2
# One tree with multiple stems stem <- tribble( ~TreeID, ~StemID, ~DBH, "1", "1.1", 11, "1", "1.2", 12 ) abundance(stem)
#> Warning: `treeid`: Duplicated values were detected. Do you need to pick main stems?
#> # A tibble: 1 x 1 #> n #> <int> #> 1 2
# Skip R CMD check for speed # \donttest{ # Similar but more realistic assert_is_installed("fgeo.x") stem <- fgeo.x::download_data("luquillo_stem5_random") abundance(stem)
#> Warning: `treeid`: Duplicated values were detected. Do you need to pick main stems?
#> # A tibble: 1 x 1 #> n #> <int> #> 1 1320
abundance(pick_main_stem(stem))
#> Warning: The `add` argument of `group_by()` is deprecated as of dplyr 1.0.0. #> Please use the `.add` argument instead. #> This warning is displayed once every 8 hours. #> Call `lifecycle::last_warnings()` to see where this warning was generated.
#> # A tibble: 1 x 1 #> n #> <int> #> 1 1000
# } 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)
#> Warning: `treeid`: Duplicated values were detected. Do you need to pick main stems?
#> Warning: `censusid`: Multiple values were detected. Do you need to group by censusid?
#> Warning: `plotname`: Multiple values were detected. Do you need to pick a single plot?
#> # A tibble: 1 x 1 #> n #> <int> #> 1 2
# 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))
#> # A tibble: 2 x 5 #> CensusID TreeID StemID DBH HOM #> <dbl> <chr> <chr> <dbl> <dbl> #> 1 1 1 1.1 10 160 #> 2 1 2 2.2 30 130
abundance(main_stem)
#> # A tibble: 1 x 1 #> n #> <int> #> 1 2
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))
#> # A tibble: 2 x 5 #> # Groups: CensusID [2] #> CensusID TreeID StemID DBH HOM #> <dbl> <chr> <chr> <dbl> <dbl> #> 1 1 1 1.2 10 160 #> 2 2 1 1.2 22 130
abundance(main_stems_by_census)
#> # A tibble: 2 x 2 #> # Groups: CensusID [2] #> CensusID n #> <dbl> <int> #> 1 1 1 #> 2 2 1
# basal_area() ------------------------------------------------------------ # Data must have a column named dbh (case insensitive) basal_area(data.frame(dbh = 1))
#> # A tibble: 1 x 1 #> basal_area #> <dbl> #> 1 0.785
# * Warns if it detects multiple values of censusid or plotname # * Also warns if it detects duplicated values of stemid basal_area(vft)
#> Warning: `stemid`: Duplicated values were detected. Do you need to pick largest `hom` values?
#> Warning: `censusid`: Multiple values were detected. Do you need to group by censusid?
#> Warning: `plotname`: Multiple values were detected. Do you need to pick a single plot?
#> # A tibble: 1 x 1 #> basal_area #> <dbl> #> 1 157.
# First you may pick the main stemid of each stem (main_stemids <- pick_main_stemid(vft2))
#> # A tibble: 3 x 5 #> CensusID TreeID StemID DBH HOM #> <dbl> <chr> <chr> <dbl> <dbl> #> 1 1 1 1.1 10 160 #> 2 1 2 2.1 20 130 #> 3 1 2 2.2 30 130
basal_area(main_stemids)
#> # A tibble: 1 x 1 #> basal_area #> <dbl> #> 1 1100.
# You can compute by groups basal_area(by_census)
#> # A tibble: 2 x 2 #> # Groups: CensusID [2] #> CensusID basal_area #> <dbl> <dbl> #> 1 1 393. #> 2 2 493.
# Skip R CMD check for speed # \donttest{ 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 }
#> # A tibble: 2 x 3 #> # Groups: CensusID [2] #> CensusID basal_area basal_area_he #> <dbl> <dbl> <dbl> #> 1 1 393. 0.0000000393 #> 2 2 493. 0.0000000493
# }