I am trying to transpose this R script to Julia without success:
library(dplyr)
culture <- tibble(
ind = c(1, 1, 1, 2, 2, 2),
year = c(2015, 2015, 2015, 2016, 2016, 2016),
value = c(10, 20, 30, 26, 34, 67)
)
culture_w <- culture %>%
group_by(year) %>%
mutate(total = sum(value),
w = value / total)
I tried the following solution (and many others) but it gives me an error saying that :total is not in the dataframe.
using DataFrames, DataFramesMeta
culture = DataFrame(
ind = [1, 1, 1, 2, 2, 2],
year = [2015, 2015, 2015, 2016, 2016, 2016],
value = [10, 20, 30, 26, 34, 67]
)
culture_w = @by culture [:year, :ind] begin
:total = sum(:value)
:w = :value ./ :total
end