how to count the amount of repeatable string?

example dataframe likes this:
dataframe <- (consultants_name = c(CHINA, USA ,JAPAN, BRITISH, BRITISH, USA ,USA, BRITISH,CHINA,JAPAN ,JAPAN, BRITISH,etc),
goods = c(computers, phone , telescopes , bowls , footballs, telescopes , computers,etc))

i want to count the amount of categories of goods from different countries, like china have 2 kinds of goods

I type the function below, help me correct them and explain it to me, thinks a lot.

dataframe %>%
group_by (country_name) %>%
summarise(amount of goods = count(country_name))

R notes to me that an error occurred in group 1: country name = "CHINA"
Does means that I have used group_by() and do not use count() in group_by() again?

As a start, place every string in quotes, be sure you have the same number of consultants_name as goods, load library(dplyr), don't use country_name if you are using consultants_name, and don't define amount of goods with spaces but rather as amount_of_goods

In addition to what fcas80 says, you may be using the wrong function: within summarise(), you want to use n() to count the number of rows in the group; otherwise count() is a shortcut where:

df %>% count(a, b) is roughly equivalent to df %>% group_by(a, b) %>% summarise(n = n())

(from ?count)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.