Reputation: 55
I have a csv files containing species names from several different families and I am computing the Shannon index. The way that I am coding it on R makes me have to count each species from each family as number tally. Is there any way I can implement some code to give me a count of each species from each family?
I am not sure where to even start or if its even possible for R to do this. Any light on the situation would be greatly appreciated.
Here is my csv file: https://www.dropbox.com/s/9e6mdu319a6071t/ALLdataCLEANED.csv?dl=0
Thanks!
Upvotes: 0
Views: 271
Reputation: 7856
There are many ways to do this job in R.
dt<-read.csv("~/Downloads/ALLdataCLEANED.csv")
1.Base R
aggregate(latitude~family+sciname,data=dt, length)
2.Package data.table
library(data.table)
setDT(dt)[, lapply(.SD, length), by=c("family", "sciname"), .SDcols="latitude"]
3.Package dplyr
library(dplyr)
dt %>%
group_by (family, sciname) %>%
summarise(n=length(latitude))
Upvotes: 1