Essentials of Research Planning
Massasoit Land Use Research and Data Collection Planning
Date: October, 2014
Author: Sean Kent
Using R to plan out the collection of aquatic invertebrates and water samples
Overarching research question: How does land use and sustainable landscaping influence ecosystem services and native biodiversity?
Last week, we examined how to create a mock dataset to plan out the experiment that examined how large the impact of sustainable landscaping was on essential pollinators, native bees, specifically by asking “Does native bee diversity, richness, and abundance decline with distance from the native plantings?”. Check out this great page for more background on using R in data planning techniques. Here, you will need to create the following variables (if necessary, create other variables that are not on this list)
- Study Site
- Variable(s) for the water quality parameters you will be testing
- Variable(s) for the aquatic and soil invertebrates that you will be collecting
Review: How do you create a variable?
Recall from last week, to create a variable for the location of bee bowls in the distance experiment, the following code in R was used. We had 10 different locations and 15 bowls placed at each location.
Location <- rep(c("EdgeAdmin(0m)", "MeadowAdmin(20m)", "FarMeadow(20m)", "FarEdge(0m)", "20m", "40m", "60m", "80m", "100m","120m"), c(15,15,15,15,15,15,15,15,15,15))
How do you create a variable filled with random numbers?
Let’s take a look at how to create a vector filled with random numbers
WaterTemperature <- rnorm(150, mean = 25, sd = 10)
The WaterTemperature” vector will have a lenght of 150 with values that have a mean of 25 and standard deviation of 10. Use this example code to create and fill up vectors to plan out the water quality and biodiversity data collection.
Review: How do you create an empty vector?
Let’s say you want to create an vector that is empty (no values), you can use the following code example. Notice how I the lenght of the vector isn’t directly identified, ie. “length = 150”, but is “length = length(Location) ”, which makes sure that the lenght of this vector is as long as another vector that you are using.
WaterTemperature1 <- vector(mode = 'numeric', length = length(Location))
We need to take each separate vector and combine them into a dataframe. To do that, we will use the
data.frame() function. Here is a quick example of how to create a dataframe of two vectors.
a <- c(1,2,3,4) b <- c("Yes", "Yes", "No", "No") DataFrame <- data.frame(a,b) a
##  1 2 3 4
##  "Yes" "Yes" "No" "No"
## a b ## 1 1 Yes ## 2 2 Yes ## 3 3 No ## 4 4 No
To export the file, we use the
DataFrame <- data.frame(a,b) write.csv(DataFrame, "DataFrameExample.csv")