DEV Community

CoderLegion
CoderLegion

Posted on • Edited on • Originally published at kodblems.com

1

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

🎉 Before you dive into this article...

🚀 Check out our vibrant new community at CoderLegion.com!

💡 Share your knowledge, connect with like-minded developers, and grow together.

👉 Click here to join now!

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

Thanks in advance

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

sum("a")

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-

library(dplyr)
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

Thnks

👋 While you are here

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay