0

I'm trying to calculate Simpson's diversity() index for different species (column headings) however I would need to compare the indices between the two treatments. I have treatments in rows and species in the columns:

         treatment  plot pinus abies
          <chr>    <int> <dbl> <dbl>
1        control     1  0.54  0.01
2        logging     2  0.02  0.09

Is there a way to do this? All the examples I've found just have species in columns (dune, BCI). Thanks for the help.

Richard Telford
  • 9,558
  • 6
  • 38
  • 51
lkaarakk
  • 11
  • 3
  • You also seem to have species in columns (`pinus` , `abies`). So you can calculate diversity indes for these, but you have to be careful that you only include your species data in calculations and exclude variables like `treatment` and `plot`. Would your data be differently organized (species by rows), you could set `MARGIN=2` in your `diversity` command. This will give you a single diversity value for each row, and then you can use your `treatment` to compare these. – Jari Oksanen Sep 12 '17 at 06:24
  • @JariOksanen Thank you!! I will look into that! Lilli – lkaarakk Sep 12 '17 at 16:27
  • So I tried to tranpose the data so that the species are in rows and added a command MARGIN=2 to the diversity command. This did not work. I cannot figure out a way to "ignore" the first column, which includes the species names in the diversity calculations. – lkaarakk Oct 04 '17 at 19:38
  • You should not do both: if you these twice, you get back from the starting point. It is *either* transpose *or* set `MARGIN`. You need numeric data for diversities. You should tell the function which columns have numbers to use in calculations. In your case this may be `yourdata[, -c(1,2)]`. Assuming the thing you have is a data frame and first two columns must be skipped. If it is a tibble or something equally strange, contact those guys to ask how to handle the result (and you may need **dplyr** or something else I have never seen). – Jari Oksanen Oct 05 '17 at 12:33

0 Answers0