This document is a work in progress, please give us feedback

1 Merging data frames

1.2 Exploring data

## [1] 100   7
## [1] 400   2
##                 species Wood_density   Leaf_N      SLA   Seed_mass
## 1   Macleania rupestris    0.5391685 11.87024  5.23328    2.053831
## 2  Coleostephus myconis    0.7003753 24.43410 20.92570    0.320000
## 3 Guatteria oliviformis    0.5007774 23.54603 16.30982  127.082572
## 4      Myrsine africana    0.6390519 12.90000 11.62415   11.700000
## 5  Chrysophyllum viride    0.6985341 18.14058 12.88736 2000.000000
## 6    Ouratea hexasperma    0.7447541 15.80000  7.29000  147.924327
##       Height    Leaf_P
## 1  2.4750017 0.7073387
## 2  0.4907508 1.9359780
## 3 16.5535877 1.1148200
## 4 15.2099828 0.8675000
## 5 17.4286478 0.7873025
## 6  7.4563818 0.7630000
##                 species                Biome
## 1 Acacia_podalyriifolia         Moist_Forest
## 2           Acer_rubrum   Coniferous_Forests
## 3           Acer_rubrum             Savannas
## 4           Acer_rubrum                Taiga
## 5           Acer_rubrum Temperate_Grasslands
## 6           Acer_rubrum      Temperate_Mixed
## 
## FALSE 
##   100
## [1] Macleania rupestris   Coleostephus myconis  Guatteria oliviformis
## [4] Myrsine africana      Chrysophyllum viride  Ouratea hexasperma   
## 100 Levels: Acacia podalyriifolia Acer rubrum ... Yucca rostrata
## [1] Acacia_podalyriifolia Acer_rubrum           Acer_rubrum          
## [4] Acer_rubrum           Acer_rubrum           Acer_rubrum          
## 114 Levels: Abarema_curvicarpa Abies_vejarii ... Yucca_rostrata

1.3 Matching variables and formats

## [1] "Macleania_rupestris"   "Coleostephus_myconis"  "Guatteria_oliviformis"
## [4] "Myrsine_africana"      "Chrysophyllum_viride"  "Ouratea_hexasperma"
## 
## FALSE  TRUE 
##     1    99
## 
## FALSE  TRUE 
##    15    99

1.4 Merging data frames

##                 species Wood_density   Leaf_N       SLA Seed_mass   Height
## 1 Acacia_podalyriifolia         0.68 26.72163  6.344215  32.65056 23.80193
## 2           Acer_rubrum         0.49 16.94147 20.501333  22.76456 36.99420
## 3           Acer_rubrum         0.49 16.94147 20.501333  22.76456 36.99420
## 4           Acer_rubrum         0.49 16.94147 20.501333  22.76456 36.99420
## 5           Acer_rubrum         0.49 16.94147 20.501333  22.76456 36.99420
## 6           Acer_rubrum         0.49 16.94147 20.501333  22.76456 36.99420
##      Leaf_P                Biome
## 1 0.7857099         Moist_Forest
## 2 1.1150000 Temperate_Grasslands
## 3 1.1150000   Coniferous_Forests
## 4 1.1150000                Taiga
## 5 1.1150000      Temperate_Mixed
## 6 1.1150000             Savannas

Is there a difference between data frame DF1 and DF2?

1.5 Challenge

Include the Growth form information into the Trait_biomes_df data frame. Remember to check first the format and names of the variables you want to match between the two data frames.

2 Functions practice

Let’s recap the main structure of a function in R!

## [1] "function (x, y = 1) " "{"                    "    x + y"           
## [4] "}"
## {
##     x + y
## }
## <environment: R_GlobalEnv>
## [1] 3
## [1] 10

2.1 Let’s practice

Extracting the mean values of seed mass per family in Moist forest

## # A tibble: 28 x 2
##    FAMILY_STD       Mean_Trait
##    <fct>                 <dbl>
##  1 Amaranthaceae        2.71  
##  2 Anacardiaceae       13.0   
##  3 Annonaceae        2242.    
##  4 Apiaceae             0.731 
##  5 Bignoniaceae        14.1   
##  6 Brassicaceae         0.339 
##  7 Burseraceae        269.    
##  8 Caricaceae           6.00  
##  9 Chrysobalanaceae  2425.    
## 10 Cyperaceae           0.0210
## # ... with 18 more rows

2.1.1 Challenge

  1. Create a function that takes any biome name as input and display the average value of seed mass per family

  2. Modify the function to calculate the average value of any trait

  3. Complete the ---- in the following code to create a function that:

  1. Takes as input the name of a biome
  2. Evaluate if this biome has species that belong to the family of true grasses (i.e., Poaceae)
  3. Return the list of true grass species
  4. If there are no grass species, returns a message “No grasses found in this biome”