If you are interested, tidyverse syntax is more human-readable.
library(dplyr)
# Sample data on a copy/paste friendly format
sample_df <- data.frame(
ID = c(1, 2, 3, 1, 2, 3),
Date = c("2015-01-01","2015-01-01","2015-01-01",
"2015-01-02","2015-01-02","2015-01-02"),
Value = c(1000, 5000, 2500, 3000, 6000, 3000)
)
sample_df %>%
group_by(Date) %>%
mutate(market_value = Value / sum(Value))
#> # A tibble: 6 x 4
#> # Groups: Date [2]
#> ID Date Value market_value
#> <dbl> <chr> <dbl> <dbl>
#> 1 1 2015-01-01 1000 0.118
#> 2 2 2015-01-01 5000 0.588
#> 3 3 2015-01-01 2500 0.294
#> 4 1 2015-01-02 3000 0.25
#> 5 2 2015-01-02 6000 0.5
#> 6 3 2015-01-02 3000 0.25
Created on 2020-05-14 by the reprex package (v0.3.0)
If you want to learn how to use this set of tools you can read this free book.