I am mutating a column in a data frame and I have a question. I am getting the sum of sales points as a calculation of Market Capitalization. I know this isn't what market cap is; just go with it please. I have sales data that goes back a long time. Right now I am just filtering out all sales points that did not occur within one year to get the sum values within a year. I am wondering if there is any way I can require only within the mutate that it sums only values within 1 year while also continuing to keep all prior sales points from the cards which meet the market cap requirements. I feel like I am overexplaining this, hopefully, you get the picture. Also, I did my best to do a reprex. This is my first one so be gentle.
library(tibble) library(tidyverse) library(quantreg) #> Loading required package: SparseM #> #> Attaching package: 'SparseM' #> The following object is masked from 'package:base': #> #> backsolve mickey_mantle_example <- tribble( ~graded_title, ~sale_date, ~price, 'Mickey Mantle', "2017-08-20", 10000, 'Mickey Mantle', "2018-09-20", 10000, 'Mickey Mantle', "2019-02-18", 10000, ) mickey_mantle_example %>% mutate(sale_date = as.Date(sale_date)) #> # A tibble: 3 x 3 #> graded_title sale_date price #> <chr> <date> <dbl> #> 1 Mickey Mantle 2017-08-20 10000 #> 2 Mickey Mantle 2018-09-20 10000 #> 3 Mickey Mantle 2019-02-18 10000 blue_chips_example <- mickey_mantle_example %>% filter(sale_date >= as.Date("2018-07-08")) %>% group_by(graded_title) %>% mutate(Market_Cap = sum(price)) %>% filter(Market_Cap >= 10000) blue_chips_example #> # A tibble: 2 x 4 #> # Groups: graded_title  #> graded_title sale_date price Market_Cap #> <chr> <chr> <dbl> <dbl> #> 1 Mickey Mantle 2018-09-20 10000 20000 #> 2 Mickey Mantle 2019-02-18 10000 20000