I am performing a routine in R, where I need to sum a variable by group. I saw this post and used aggregate
. It works fine when I hardcode
the column names such as Category
and Frequency
.
Category Frequency
First 10
First 15
First 5
Second 2
Third 14
Third 20
Second 3
But, my situation is that, these column names must be assigned dynamically
in run-time. These columns are created during run-time based on some manipulation. So, if I try to access the column name with a variable like this -
x_axis_column <- input$x_axis
and try to use the aggregate function, I get an error as shown below -
Error in FUN: invalid 'type' (character) of argument
This is the code that I tried -
counted <- aggregate(item~x_axis_column, data, sum)
What am I doing wrong here?