While LoopsOctober 12, 2016Occasionally you may wish to carry out a function or operation until a certain condition if filled. This can be done with a while loop.
Once n has reached 6 the loop no longer continues to operate. This may be a simple example, but it can be applied in many complex situations.
0 Comments
Calculating species richness from a matrix of species abundancesOctober 7, 2016Here I demonstrate how to calculate species richness from species abundance or cover data. I’ll use a vegetation cover dataset from Bryce Canyon National Park: http://ecology.msu.montana.edu/labdsv/R/labs/lab2/lab2.html
We can see that the data are organized by rows of sites, and each site has plant cover data, organized by species into columns. Because this is cover data and not occurrence data (1s and 0s), we can’t just sum all of the values across each row to calculate species richness for each site. Instead, we have to tally all of the non-zero occurrences across rows. To do this, we use the built in
We can now examine the distribution and summary statistics of species richness across sites in Bryce Canyon.
Package stringr: String SplitSeptember 27, 2016Sometimes it is necessary to take apart a string. The str_split() function in the stringr package allows you to do that.
Let’s use the example dataset Loblolly in r
Here in the first column we have the height of the trees in ft. Lets say that we want to convert this to two columns one for feet and another for inches. (Note: There are quite a few ways to do this, but here we use this method to show off the str_split() function.)
|
Spatial Ecology @ MSUClick on "Category" below to search for R code compiled by the Zarnetske Spatial & Community Ecology Lab and students in MSU's Spatial Ecology graduate course (FOR870/FW870) Category
All
Archive
October 2016
|