Conditionally Count in dplyr
Try
library(dplyr)
memberorders %>%
group_by(MemID) %>%
summarise(sum2= sum(value[week<=2]), sum4= sum(value[week <=4]),
count2=sum(week<=2), count4= sum(week<=4))
Using both previous ideas and keeping it consistent:
library(tidyverse)
MemberLTV_2 <- memberorders %>%
group_by(MemID) %>%
summarize(
count2 = length(value[week<=2]),
count4 = length(value[week<=4]),
sum2 = sum(value[week<=2]),
sum4 = sum(value[week<=4])
)