ropensci / allodb

An R package for biomass estimation at extratropical forest plots.
https://docs.ropensci.org/allodb/
GNU General Public License v3.0
36 stars 11 forks source link

adding a new common column (and changing the title of a column) #52

Closed gonzalezeb closed 6 years ago

gonzalezeb commented 6 years ago

How do I add a column that need to show in both tables equations and sitespecies? Or, for example, the column proxy_species, currently in sitespecies need to change its name to something like taxa-equation and will indicate the "species or group of plants for which the allometry was developed". Then that column need to also show in the equation table (because if I am not a forestgeo site I just would like to explore the equation table with taxa names on it)

As we rewrite data.Rmd to read from the splitted csv files (still not done) I have not idea how to get it done if not reading the master table.

maurolepore commented 6 years ago

I'm happy to edit data.Rmd to read from the split .csv whenever you are ready to start editting the split .csv files instead of the master table. I wait for you green flag.

RE:

I just would like to explore the equation table with taxa names on it

To explore columns from more than one table you would first join them. See below. For more ways of joining tables I recommend http://r4ds.had.co.nz/relational-data.html.

For users' convenience, we could write join_all_tables(), which would create a master table on the fly. Also, we could write a widget similar to this one https://shiny.rstudio.com/gallery/datatables-demo.html

library(allodb)
suppressPackageStartupMessages(library(dplyr))

joint <- left_join(equations, sitespecies)
#> Joining, by = c("equation_id", "dependent_variable_biomass_component", "allometry_specificity", "dbh_min_cm", "dbh_max_cm")
joint %>% 
  filter(!is.na(proxy_species)) %>% 
  select(equation_id, equation_allometry, proxy_species)
#> # A tibble: 110 x 3
#>    equation_id equation_allometry               proxy_species       
#>    <chr>       <chr>                            <chr>               
#>  1 cf733d      exp(5.67+1.97*dbh+1*log(dbh))    Cornus florida      
#>  2 cf733d      exp(5.67+1.97*dbh+1*log(dbh))    Cornus florida      
#>  3 122ba6      3.203+(-0.234*dbh)+0.006*(dbh^2) Fraxinus americana  
#>  4 122ba6      3.203+(-0.234*dbh)+0.006*(dbh^2) Fraxinus americana  
#>  5 c36a5b      0.1632*(dbh^2.2454)              Juniperus virginiana
#>  6 c36a5b      0.1632*(dbh^2.2454)              Juniperus virginiana
#>  7 8aecca      10^(1.1981+1.5876*(log10(dbh)))  Prunus serotina     
#>  8 8aecca      10^(1.1981+1.5876*(log10(dbh)))  Prunus serotina     
#>  9 8aecca      10^(1.1981+1.5876*(log10(dbh)))  Prunus serotina     
#> 10 8aecca      10^(1.1981+1.5876*(log10(dbh)))  Prunus serotina     
#> # ... with 100 more rows

Created on 2018-10-02 by the reprex package (v0.2.1)

maurolepore commented 6 years ago

Closing. @gonzalezeb and I have just talked over the phone and we seem clear on what to do. Should we need to discuss further, we can reopen later.