[英]How can I distinct count values in a column in R
I have something like this:我有这样的事情:
# A tibble: 24,288 x 1
Country/Region
Afghanistan阿富汗
Albania阿尔巴尼亚
Algeria阿尔及利亚
Andorra安道尔
Angola安哥拉
Antigua and Barbuda Argentina安提瓜和巴布达 阿根廷
Armenia亚美尼亚
Australia澳大利亚
Australia澳大利亚
How can I count the different values in this tibble?我如何计算这个小标题中的不同值?
We can use count
from dplyr
我们可以使用dplyr
的count
library(dplyr)
df1 %>%
count(`Country/Region`)
Here's the sqldf solution:这是 sqldf 解决方案:
textFile <- "Country_Region
Afghanistan
Albania
Algeria
Andorra
Angola
Antigua and Barbuda Argentina
Armenia
Australia
Australia"
data <- read.csv(text = textFile,stringsAsFactors = FALSE)
library(sqldf)
sqldf("select count(distinct Country_Region) from data")
...and the result: ...结果:
> sqldf("select count(distinct Country_Region) from data")
count(distinct Country_Region)
1 8
>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.