forestgeo / fgeo.tool

[R-package on CRAN] General purpose tools for ForestGEO Packages
https://forestgeo.github.io/fgeo.tool
Other
2 stars 6 forks source link

Clarify the difference between pick_main_stem() and *stemid() #93

Closed maurolepore closed 5 years ago

maurolepore commented 5 years ago

See https://github.com/forestgeo/forum/issues/19#issuecomment-442810575

maurolepore commented 5 years ago

RE: forestgeo/forum#19

I replaced the old example with this one.

library(fgeo)
#> -- Attaching packages ---------------------------------------------------------------- fgeo 0.0.0.9002 --
#> v fgeo.x       0.0.0.9000     v fgeo.analyze 0.0.0.9003
#> v fgeo.plot    0.0.0.9402     v fgeo.tool    0.0.0.9005
#> -- Conflicts ------------------------------------------------------------------------ fgeo_conflicts() --
#> x fgeo.tool::filter() masks stats::filter()

# One `treeID` with multiple stems.
# `stemID == 1.1` has two measurements (due to buttresses).
# `stemID == 1.2` has a single measurement.
census <- tribble(
    ~sp, ~treeID, ~stemID,  ~hom, ~dbh, ~CensusID,
  "sp1",     "1",   "1.1",   140,   40,         1,  # main stemID (max `hom`)
  "sp1",     "1",   "1.1",   130,   60,         1,
  "sp1",     "1",   "1.2",   130,   55,         1   # main stemID (only one)
)

# Picks a unique row per unique `treeID`
pick_main_stem(census)
#> # A tibble: 1 x 6
#>   sp    treeID stemID   hom   dbh CensusID
#>   <chr> <chr>  <chr>  <dbl> <dbl>    <dbl>
#> 1 sp1   1      1.1      140    40        1

# Picks a unique row per unique `stemID`
pick_main_stemid(census)
#> # A tibble: 2 x 6
#>   sp    treeID stemID   hom   dbh CensusID
#>   <chr> <chr>  <chr>  <dbl> <dbl>    <dbl>
#> 1 sp1   1      1.1      140    40        1
#> 2 sp1   1      1.2      130    55        1

Created on 2018-12-30 by the reprex package (v0.2.1)