0

I have a dataset called country_num that looks like this

Country num Other 5 Other 6 Other 16 USA 30 UK 25 China 12 

I tried to use group_by to combine the three "Other" rows like this

country_num %>% group_by(Country) %>% count(num) 

But the three "Other" rows did not aggregate. Why is that and what can I do about it?

1
  • 2
    What is your expected output? Are you trying to sum the num values? country_num %>% group_by(Country) %>% summarise(num = sum(num)) Commented Jun 18, 2021 at 4:05

1 Answer 1

1

Edit

This answer is basically what @Ronak Shah said in his comment above.

--

Is this what you want?

library(tidyverse) country_num <- read.table( text = "Country num Other 5 Other 6 Other 16 USA 30 UK 25 China 12", header = TRUE ) country_num %>% group_by(Country) %>% summarise(num = sum(num), n = n()) # A tibble: 4 x 3 # Country num n # <chr> <int> <int> #1 China 12 1 #2 Other 27 3 #3 UK 25 1 #4 USA 30 1 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.