PNNL-PREMIS / SULI2019

Repository for summer 2019 SULI interns
0 stars 0 forks source link

R workshop 2019-07-02 practice #31

Open stephpenn1 opened 5 years ago

stephpenn1 commented 5 years ago

Question 1: add comments before each code chunk explaining what is happening in this function

make_tree_data <- function(inventory_data, species_codes, plot_data) {

  inventory_data %>% 
    left_join(species_codes, by = "Species_code") ->
    trees

  unmatched <- filter(trees, is.na(Species))
  if(nrow(unmatched)) {
    warning("Species codes not found:", unique(unmatched$Species_code))  
  }

  trees %>% 
    filter(Site == "SERC") %>% # temporary - only handle SERC
    left_join(select(plot_data, Site, Plot, Plot_area_m2), by = c("Site", "Plot")) 
}
bpbond commented 5 years ago

Question 2: What does the following print? Why?

> f <- function(a) { print(a) }
> a <- 2
> f(1)
stephpenn1 commented 5 years ago

Question 3: Challenge problem

Pythagorean theorem: a2+b2=c2 Write a function that, given the lengths of two sides of the triangle, calculates the length of the third side.

(from https://cfss.uchicago.edu/homework/programming/)