I am trying to count the number of rows by group in a DataFrame. The following code generates a new column, called x1, which which has the intended information:
by(df, [:grouping_var_1, :grouping_var_2], nrow)
However, I am not aware on how to generate such column in a way I can define a name other than x1. The solution I have found so far is:
@pipe df |> by(_, [:grouping_var_1, :grouping_var_2], nrow) |> rename(_, :x1 => :my_desired_name);
Is there anyway I could do this directly without having to use rename ?
Thanks in advance.