DEV Community


Posted on • Originally published at


error in fun(newx[, i], ...) : invalid 'type' (character) of argument

Hi, I want someones' help me on this " error in fun(newx[, i], ...) : invalid 'type' (character) of argument"

Thanks in advance

In this case, this error is coming from sum(), since you are trying to sum the character elements in the color column.


Error in sum("a") : invalid 'type' (character) of argument

You require to remove the color column from the x argument, because it is not being employed in aggregation, however is really the by argument.

aggregate(csv[-1], csv["color"], sum)

color val2 val3

1 blue 6 13

2 green 7 3

3 red 11 9

However, you can try this formula method. It can solve your problem.

aggregate(. ~ color, csv, sum)
You can also apply dplyr package for example-

csv %>% group_by(color) %>% summarise_each(funs(sum))
color val2 val3
(chr) (int) (int)
1 blue 6 13
2 green 7 3
3 red 11 9
Now, you are able to solve this issue


Top comments (0)

Timeless DEV post...

Git Concepts I Wish I Knew Years Ago

The most used technology by developers is not Javascript.

It's not Python or HTML.

It hardly even gets mentioned in interviews or listed as a pre-requisite for jobs.

I'm talking about Git and version control of course.

One does not simply learn git