简体   繁体   English

如何区分 R 列中的计数值

[英]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澳大利亚

... with 24,278 more rows ...还有 24,278 行

How can I count the different values in this tibble?我如何计算这个小标题中的不同值?

We can use count from dplyr我们可以使用dplyrcount

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.

相关问题 如何获得 R 列中前 20 个不同的值 - How can I get the top 20 distinct values in a column in R 如何对R中特定列中的值的不同出现进行分组和计数? - How to group by and count distinct occurences of values in a particular column in R? 如何计算R中带有条件的数据框列中不同值的数量 - How to Count the Number of Distinct Values in a Data Frame Column with a Condition in R 使用 R aggregate() function,我如何计算不同的值? - Using R aggregate() function, how do I count distinct values? 如何按 r 中的一列中的不同值进行分组,以便生成密度图? - How to group by distinct values in one column in r so I can generate a density plot? 有效地找到R中数据框中不同行的列值计数 - Efficiently finding the count of column values for distinct rows in a dataframe in r R分组依据| 计算按另一列分组的不同值 - R group by | count distinct values grouping by another column 在 R 中添加不同值的列并计数到相同的小标题 - Add column for distinct values and count to same tibble in R 如何根据另一个列标准计算列的不同值的数量? - How do I count the number of distinct values of a column based on another column criterion? 如何在r中按组中的df创建一个具有唯一值计数的新列 - How can I create a new column with a count of unique values in df by group in r
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM