1
votes

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

How can I count the different values in this tibble?

2
Do you need n_distinct(df$`Country/Region`) or length(unique(df$`Country/Region`)) or uniqueN(df$`Country/Region`) ? All of them count distinct values in the column.Ronak Shah

2 Answers

1
votes

We can use count from dplyr

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

Here's the sqldf solution:

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
>