有没有办法从csv计数R中的文本? [英] Is there a way to count text in R from csv?
问题描述
我有一个csv文件包含来自几个不同家庭的物种名称,我计算的香农指数。我在R上编码的方式使我必须计数每个家庭的每个物种作为数字计数。有没有什么办法,我可以实现一些代码,给我每个家庭的每个物种的数量?
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?
我不知道在哪里甚至开始, R做到这一点。任何光的情况都会非常感激。
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.
这是我的csv档案: https://www.dropbox.com/s/9e6mdu319a6071t/ALLdataCLEANED.csv?dl=0
Here is my csv file: https://www.dropbox.com/s/9e6mdu319a6071t/ALLdataCLEANED.csv?dl=0
谢谢!
推荐答案
有很多方法可以在R中完成这项工作。
There are many ways to do this job in R.
dt<-read.csv("~/Downloads/ALLdataCLEANED.csv")
b $ b
1.Base R
1.Base R
aggregate(latitude~family+sciname,data=dt, length)
2.Package data.table
2.Package data.table
library(data.table)
setDT(dt)[, lapply(.SD, length), by=c("family", "sciname"), .SDcols="latitude"]
3.Package dplyr
3.Package dplyr
library(dplyr)
dt %>%
group_by (family, sciname) %>%
summarise(n=length(latitude))
这篇关于有没有办法从csv计数R中的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!