# Provide the standardized trait values per observation, together with species names
# and the georeferences of the sampling site (Latitude and Longtude), if availalbe,
# in a wide table format. Several steps are necessary:
# 1. Select only the trait records that have standardized numeric values.
# The complete.cases() is used to ensure the cases are complete, i.e. have no
# missing values.
num_traits <- rtry_select_row(data_TRY_15160,
complete.cases(TraitID) & complete.cases(StdValue))
# 2. Select the relevant columns for transformation.
num_traits <- rtry_select_col(num_traits,
ObservationID, AccSpeciesID, AccSpeciesName, TraitID, TraitName,
StdValue, UnitName)
# 3. Extract the values of georeferences and the corresponding ObservationID.
lat <- rtry_select_anc(data_TRY_15160, 59)
lon <- rtry_select_anc(data_TRY_15160, 60)
# 4. Merge the relevant data frames based on the ObservationID using rtry_join_left().
num_traits_georef <- rtry_join_left(num_traits, lat, baseOn = ObservationID)
num_traits_georef <- rtry_join_left(num_traits_georef, lon, baseOn = ObservationID)
# 5. Perform wide table transformation of TraitID, TraitName and UnitName based on
# ObservationID, AccSpeciesID and AccSpeciesName with cell values from StdValue.
# If several records with StdValue were provided for one trait with the same
# ObservationID, AccSpeciesID and AccSpeciesName, calculate their mean.
num_traits_georef_wider <- rtry_trans_wider(num_traits_georef,
names_from = c(TraitID, TraitName, UnitName),
values_from = c(StdValue),
values_fn = list(StdValue = mean))
# Expected messages:
# dim: 150 28
# dim: 150 7
# col: ObservationID AccSpeciesID AccSpeciesName TraitID TraitName
# StdValue UnitName
#
# dim: 98 2
# col: ObservationID Latitude
#
# dim: 97 2
# col: ObservationID Longitude
#
# dim: 150 8
# col: ObservationID AccSpeciesID AccSpeciesName TraitID TraitName
# StdValue UnitName Latitude
#
# dim: 150 9
# col: ObservationID AccSpeciesID AccSpeciesName TraitID TraitName
# StdValue UnitName Latitude Longitude
#
# dim: 146 7
# Learn more via the vignette (Workflow for general data preprocessing using rtry):
# vignette("rtry-workflow-general")
Run the code above in your browser using DataLab