I have a dataset and I want to reshape it with package reshape2 from R, but I'm getting this error:
Aggregation function missing: defaulting to length
This is the head() of my data:
cat_one customer valor
cama A 1
cama B 1
cama C 1
mesa D 1
mesa A 1
mesa A 1
And I want to reshape it like this, with a count between both variables:
customer cama mesa
A 1 0
B 2 ...
C
D ... ...
This is my code:
dcast(dados_teste, cat_one ~ customer, value.var = 'valor')
And I'm following this other question, but the same solution is not working for me.
You've mixed up the LHS and RHS of the formula.
Try:
The "error" that you refer to is actually just a
warning
that tells you that it is just counting the number of values--not applying any other function. So, in this case, it's perfectly acceptable.If you want to get rid of it, specify
fun.aggregate = length
.If its just counts of two columns that you're after, you could also look at
table
: