Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8506171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:31:19+00:00 2026-06-11T02:31:19+00:00

How do you use aggregate if your unique column ID is a character? aggregate(data,

  • 0

How do you use aggregate if your unique column ID is a character?

aggregate(data, list(data$colID), sum)
Error in Summary.factor(c(1L, 1L), na.rm = FALSE) : 
  sum not meaningful for factors

Change to character..

data$colID<-as.character(data$colID)

aggregate(data, list(data$colID), sum)
Error in FUN(X[[1L]], ...) : invalid 'type' (character) of argument

ddply I get a similar error.  
Error in FUN(X[[1L]], ...) : 
  only defined on a data frame with all numeric variables

I only want to aggregate by the colID, I dont want to sum it. I want all the other columns to sum.

dput(data)
structure(list(colID = structure(c(1L, 1L, 1L, 2L, 2L), .Label = c("a", 
"b"), class = "factor"), col1 = c(1, 0, 0, 0, 2), col2 = c(0, 
1, 0, 2, 0), col3 = c(0, 0, 1, 0, 0), col4 = c(5, 5, 5, 7, 7)), .Names = c("colID", 
"col1", "col2", "col3", "col4"), row.names = c(NA, -5L), class = "data.frame")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:31:21+00:00Added an answer on June 11, 2026 at 2:31 am

    This should work

    aggregate(x = DF[, -1], by = list(DF$colID), FUN = "sum")
    

    Where DF is your data.frame

    Using ddply from plyr package

    ddply(DF, .(colID), numcolwise(sum))
    
       colID col1 col2 col3 col4
    1     a    1    1    1   15
    2     b    2    2    0   14
    

    usign either acast or dcast from reshape2 package

    acast( melt(DF), variable ~ colID, sum)  # a matrix
    dcast( melt(DF), variable ~ colID, sum)  # a data.frame
    
    Using colID as id variables
          a  b
    col1  1  2
    col2  1  2
    col3  1  0
    col4 15 14
    

    EDIT
    Using ddply. Not so elegant, but it works!

     Sums <- ddply(DF[, -5], .(colID), numcolwise(sum))
     Mean <- ddply(DF[, c(1,5)], .(colID), numcolwise(mean))[,-1]
     cbind(Sums, col4_mean=Mean)
      colID col1 col2 col3 col4_mean
    1     a    1    1    1         5
    2     b    2    2    0         7
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the below sql statement i get the following error Cannot use an aggregate
I am searching for a solution how to use the aggregate function to sum
I'm looking for a dead simple example on how to use aggregate and calculate
trying to use this route: from(activemq:profiles).aggregate(header(cheese)).batchSize(30).bean(ProfilesQueueService, saveContacts) Fails with: No signature of method: org.apache.camel.model.RouteType.aggregate()
I have a problem and would really need your help? My data (let's name
First I'm not mad, because I use MVVM in WinForms-) I know about MVP
Whenever we use an aggregate function in SQL ( MIN , MAX , AVG
I m trying to calculate sum of a list of records. I have 3
When I try to to use new Aggregate framework from Python I got the
I figure I should use 'Aggregate' but apparently I am getting it wrong First

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.