如何区分 R 列中的计数值

How can I distinct count values in a column in R

我有这样的东西:

# A tibble: 24,288 x 1

Country/Region

阿富汗
阿尔巴尼亚
阿尔及利亚
安道尔
安哥拉
安提瓜和巴布达 阿根廷
亚美尼亚
澳大利亚
澳大利亚

...还有 24,278 行

如何计算这个小标题中的不同值?

我们可以使用 count 来自 dplyr

library(dplyr)
df1 %>%
   count(`Country/Region`)

这是 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")

...结果:

> sqldf("select count(distinct Country_Region) from data")
  count(distinct Country_Region)
1                              8
>