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

  • Home
  • SEARCH
  • 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 6203741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:58:09+00:00 2026-05-24T04:58:09+00:00

I am using ddply to aggregate my data but haven’t found an elegant way

  • 0

I am using ddply to aggregate my data but haven’t found an elegant way to assign column names to the output data frame.

At the moment I am doing this:

agg_data <- ddply(raw_data, .(id, date, classification), nrow)
names(agg_data)[4] <- "no_entries"

and this

agg_data <- ddply(agg_data, .(classification, date), colwise(mean, .(no_entries)) )
names(agg_data)[3] <- "avg_no_entries"

Is there a better, more elegant way to do this?

  • 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-05-24T04:58:09+00:00Added an answer on May 24, 2026 at 4:58 am

    You can use summarise:

    agg_data <- ddply(raw_data, .(id, date, classification), summarise, "no_entries" = nrow(piece))
    

    or you can use length(<column_name>) if nrow(piece) doesn’t work. For instance, here’s an example that should be runnable by anyone:

    ddply(baseball, .(year), summarise, newColumn = nrow(piece))
    

    or

    ddply(baseball, .(year), summarise, newColumn = length(year))
    

    EDIT

    Or as Joshua comments, the all caps version, NROW does the checking for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ddply to aggregate and summarize data frame variables, and I am
I am using ddply to split up a data frame and send the chunks
Is it possible to use spaces in ddply? I'm using data from a spreadsheet
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using R's builtin ToothGrowth example dataset, this works: ddply(ToothGrowth, .(supp,dose), function(df) mean(df$len)) But I
using chrome 15 on osx 10.6.8 When adding event listeners, I've found that putting
I have a large data.frame, and I'd like to be able to reduce it
R: how can I populate the rows of a data frame, in which each
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
I have a dataframe: > df <- data.frame( + Species = rep(LETTERS[1:4], times=c(5,6,7,6)), +

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.