Skip to contents

This function aggregates a data.frame by unique trackIDs so that each row represents a genet (unique genetic individual) in a given year.

Usage

aggregateByGenet(
  dat,
  site = "Site",
  quad = "Quad",
  species = "Species",
  year = "Year",
  trackID = "trackID",
  ...
)

Arguments

dat

An sf data.frame. Typically this is a data.frame that has been returned from the trackSpp() function, although 'dat' can be any sf data.frame of organism demographic data in which each genet is given unique identifying value (what we call here a 'trackID'). If 'dat' already only has one row for each unique trackID in each unique year (i.e. there are no vegetative individuals--no ramets), then the output of aggregateByGenet() will have the same number of rows as 'dat'. If 'dat' has multiple rows (each of which is a ramet) for the same trackID in the same year, then the output of aggregateByGenet() will have fewer rows than the input 'dat' data.frame. 'dat' MUST have columns called 'basalArea_genet', 'age', 'recruit', 'survives_tplus1', 'nearEdge', and 'size_tplus1', although they can be populated with NAs. The trackSpp() function adds these columns, so if you have made no changes to the data.frame that was returned from trackSpp(), then your data.frame should have these columns already.

site

A character string giving the name of the column in 'dat' that contains the values for site. The default is "Site".

quad

A character string giving the name of the column in 'dat' that contains the values for quadrat. The default is "Quad".

species

A character string giving the name of the column in 'dat' that contains the values for species. The default is "Species".

year

A character string giving the name of the column in 'dat' that contains the values for year. The default is "Year".

trackID

A character string giving the name of the column in 'dat' that contains the values for the unique identifier, or trackID. The default is "trackID".

...

Other arguments passed on to methods. Not currently used.

Value

An sf data.frame that has been aggregated by genet so that each row represents one unique genetic individual in one year. This data.frame has columns containing data for site, quadrat, species, year, and trackID, as well as columns called 'basalArea_genet', 'age', 'recruit', 'survives_tplus1', 'nearEdge', and 'size_tplus1'. This data.frame will most likely be shorter than the input 'dat', because a genet that was previously broken into multiple rows representing each ramet in each year will now have only one row in each year.

Details

This function is a plantTracker-specific, user-friendly wrapper for the 'aggregate' function. This function was designed for use within the trackSpp function, but can be also called independently by the user. The function is designed to take a data.frame of the same format that is returned by trackSpp(), but it can be used to aggregate any dataset by genet (or some other unique identifier), as long as there is a column that identifies genet (or unique identifier) identity for each observation.

See also

This function is called inside the trackSpp() function.

Examples

dat <- grasslandData[grasslandData$Site == c("AZ") &
 grasslandData$Species %in% c("Bouteloua rothrockii", "Calliandra eriophylla" ),]
names(dat)[1] <- "speciesName"
inv <- grasslandInventory[unique(dat$Quad)]
outDat <- trackSpp(dat = dat,
 inv = inv,
 dorm = 1,
 buff = .05,
 buffGenet = 0.005,
 clonal = data.frame("Species" = unique(dat$speciesName),
 "clonal" = c(TRUE,FALSE)),
 species = "speciesName",
 aggByGenet = FALSE
 )
#> Site: AZ
#> -- Quadrat: SG2
#> ---- Species: Bouteloua rothrockii
#> ; Calliandra eriophylla
#> Note: Individuals in year 1927 have a value of 'NA' in the 'survives_tplus1' and 'size_tplus1' columns because 1927 is the last year of sampling in this quadrat.
#> -- Quadrat: SG4
#> ---- Species: Bouteloua rothrockii
#> ; Calliandra eriophylla
#> Note: Individuals in year 1927 have a value of 'NA' in the 'survives_tplus1' and 'size_tplus1' columns because 1927 is the last year of sampling in this quadrat.

aggregateByGenet(dat = outDat,
species = 'speciesName')
#> Simple feature collection with 346 features and 11 fields
#> Geometry type: GEOMETRY
#> Dimension:     XY
#> Bounding box:  xmin: -0.001386579 ymin: -0.001017592 xmax: 1.000536 ymax: 1.001267
#> CRS:           NA
#> First 10 features:
#>    Site Quad          speciesName        trackID Year basalArea_genet recruit
#> 1    AZ  SG2 Bouteloua rothrockii  BOUROT_1922_1 1922    9.636323e-04      NA
#> 2    AZ  SG2 Bouteloua rothrockii BOUROT_1922_10 1922    1.250163e-03      NA
#> 3    AZ  SG2 Bouteloua rothrockii BOUROT_1922_11 1922    2.504885e-05      NA
#> 4    AZ  SG2 Bouteloua rothrockii  BOUROT_1922_2 1922    1.765691e-03      NA
#> 5    AZ  SG2 Bouteloua rothrockii  BOUROT_1922_3 1922    8.045954e-04      NA
#> 6    AZ  SG2 Bouteloua rothrockii  BOUROT_1922_3 1924    5.705242e-04      NA
#> 7    AZ  SG2 Bouteloua rothrockii  BOUROT_1922_3 1925    2.482590e-04      NA
#> 8    AZ  SG2 Bouteloua rothrockii  BOUROT_1922_3 1926    8.397793e-04      NA
#> 9    AZ  SG2 Bouteloua rothrockii  BOUROT_1922_3 1927    1.427247e-03      NA
#> 10   AZ  SG2 Bouteloua rothrockii  BOUROT_1922_4 1922    7.043062e-04      NA
#>    survives_tplus1 age  size_tplus1 nearEdge                       geometry
#> 1                0  NA           NA     TRUE POLYGON ((0.9556098 0.07696...
#> 2                0  NA           NA    FALSE POLYGON ((0.6691549 0.24262...
#> 3                0  NA           NA    FALSE POLYGON ((0.6470947 0.51129...
#> 4                0  NA           NA     TRUE POLYGON ((0.9843703 0.37799...
#> 5                1  NA 0.0005705242     TRUE POLYGON ((0.8766142 0.95972...
#> 6                1  NA 0.0002482590     TRUE POLYGON ((0.8232826 0.97669...
#> 7                1  NA 0.0008397793     TRUE POLYGON ((0.8734301 0.94362...
#> 8                1  NA 0.0014272470     TRUE POLYGON ((0.8896559 0.93777...
#> 9               NA  NA           NA     TRUE MULTIPOLYGON (((0.8745275 0...
#> 10               0  NA           NA    FALSE POLYGON ((0.1223214 0.70317...