complicated group_by +summarize

name place  first_time money_spent
Anna Florida TRUE          44
Anna Florida FALSE         22
Anna Florida FALSE         289
Anna Florida FALSE         0
Ryan Mexico  FALSE         0
Ryan Mexico  TRUE         122
Ryan Mexico  FALSE         0

hey all quick question. above is my data. for each group (name, place) I want to see how many times there is a non-zero, positive value in money_spent that doesn't have a first_time value as TRUE.

so when I do group_by and summarize, for group (Anne/Florida), it should be 2. Since she has a value in money_spent in two rows with first_time as FALSE that are non-zero and positive. For Ryan Mexico, it should be 0. Since he has money_spent as 0 in all rows that have first_time as FALSE.

thank you

If your dataset is df, you could do the following:

library(tidyverse)

df %>%
   group_by(name, place) %>%
   summarise(n = sum(first_time == FALSE & money_spent > 0)) %>%
   ungroup()

1 Like

period! thank you!!<3

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.