I have a tabulated data with counts in each row. I want to categorize and see the sums of each category in a table. I have used the script below:
as.matrix.data.frame(xtabs(Count ~ Factor,
data=aggregate(Count ~ Factor, data=data, FUN=sum)))
I have the error below:
Error in seq_len(p) : argument must be coercible to non-negative integer
I created a random database below whichc gives the same error:
data <- cbind(c("Factor" = factor(sample.int(n = 41, size = 18000, replace = TRUE))),
c("Count" = as.numeric(sample.int(n = 10, size = 18000, replace = TRUE))))
as.matrix.data.frame(xtabs(V2 ~ V1,
data=aggregate(V2 ~ V1, data=data, FUN=sum)))
Error in seq_len(p) : argument must be coercible to non-negative integer
In the data I see dicordance like below:
> summary(data$V2)
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.00 3.00 5.00 5.49 8.00 10.00
> summary(desc(data$V2))
Min. 1st Qu. Median Mean 3rd Qu. Max.
-10.00 -8.00 -5.00 -5.49 -3.00 -1.00
And the multiplications below does not help:
data$V1 <- (-1)*data$V1
data$V2 <- (-1)*data$V2
I want to have sum of counts sy category but I have the error.