I am trying to calculate the Simpson's Diversity Index, and I am wondering if I can keep the row names using the vegan package.
My dataset currently looks something like this:
hab Sp1 Sp2
1 habitat1 1645 1550
2 habitat2 2935 3060
3 habitat3 4780 2875
4 habitat4 3370 3500
5 habitat5 3730 2270
6 habitat6 2475 1140
7 habitat7 1405 1160
8 habitat8 6180 4145
9 habitat9 795 140
10 habitat10 4745 4595
The code I am using is:
data_simp %>%
diversity("simp")
Error in diversity(., "simp") : input data must be numeric
I managed to get the Simpson's indices for each row when I deleted the first column in my dataset. However, I would like to keep the first column to create a new dataset with the name of the 'habitat' and the correspondent Simpson's Diversity Index.
Is it possible?
Thank you :)
After watching this video on Youtube, I found the answer to my question.
I managed to run the index using the wide format of the dataset, instead of the long format.
The code:
The result: