From 2a9f213fbe8083491ee7819738dd01940f0a03f0 Mon Sep 17 00:00:00 2001 From: sldonoghue1 Date: Wed, 6 Nov 2024 11:28:40 +0000 Subject: [PATCH] Update funandloops.md Minor edits: - change variable name at line 311 - load dplyr and ggplot2 packages first (without first calling the dplyr package my filter function was not working as it was using the filter function from the stats package) --- _tutorials/funandloops.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/_tutorials/funandloops.md b/_tutorials/funandloops.md index b67d7837..f1462401 100755 --- a/_tutorials/funandloops.md +++ b/_tutorials/funandloops.md @@ -308,7 +308,7 @@ diam.summ <- function(dbh, mean = TRUE, median = TRUE, ba = TRUE){ return(as.data.frame(na.omit(t(data.frame(mean_dbh, median_dbh, mean_ba))))) } -diam.summ(dbh = bicuar_trees$diam, mean = TRUE, median = FALSE) +diam.summ(dbh = trees_bicuar$diam, mean = TRUE, median = FALSE) ``` Also note that in this function definition the extra arguments have default values, e.g. `mean = TRUE`. This means that even if the user doesn't specify what the value of `mean` should be, e.g. `diam.summ(dbh = trees_bicuar$diam, median = TRUE, mean_ba = FALSE)`, R will default to the value of `mean = TRUE`, thus calculating the mean trunk diameter. @@ -319,9 +319,11 @@ Also note that in this function definition the extra arguments have default valu This final section for the workshop provides another real world example using simple `for()` loops and functions to create multiple graphs of population trends from the [Living Planet Index](http://www.livingplanetindex.org/) for a number of vertebrate species from 1970 to 2014. Work through the example to make sure that all the code makes sense, remembering the lessons from earlier in the workshop. -First, import the data: +First, load required packages and import the data: ```r +library(dplyr) +library (ggplot2) LPI <- read.csv("LPI_data_loops.csv") ```