-1

I have a huge survey csv file, which I imported in Rstudio. Here is a sample data

User 1  User 2  Duration
5       2       7-11 months
5       5       Less than 1 month
5       5       4-6 months
5       5       4-6 months
5       4       4-6 months
5       5       2 years
4       6       1 year
4       4       4-6 months
4       8       7-11 months
4       4       2 years
3       3       Less than 1 month
3       3       7-11 months
3       3       1-3 months

I want to calculate sum of user1, filtering with duration, say 4-6 months.

Till now I have used :

df %>% group_by(Duration) %>% summarise(count=n_distinct(User1)) %>% 
  +     filter(Duration=="4-6 months")

But its not returning proper values. Please suggest me the solution.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294

1 Answers1

1

Your column name may be incorrect:

df %>%
 group_by(Duration) %>%
 summarise(sum_user1 = sum(`User 1`, na.rm = TRUE)) %>%
 filter(Duration=="4-6 months")
Josh Gilfillan
  • 4,348
  • 2
  • 24
  • 26