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 8583529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:33:35+00:00 2026-06-11T21:33:35+00:00

For a data frame populated from a SQL query which looks like this: Company

  • 0

For a data frame populated from a SQL query which looks like this:

Company        Month         Total_Count
ABC            2012-03         10
ABC            2009-01         1
DEF            2011-01         29
GHI            2001-09         10
GHI            2008-01         9
GHI            2010-09         100

I would like to come up with a summary report that would output this:

Company          Total         Months
ABC              11            10         1
DEF              29            29
GHI              119           10      9    100

where column Total would be the sum across all the months
and column Months would be the individual counts for each month encountered for that org. I would love to see if it is possible to somehow squeeze in the actual Month also. Something like:

Company          Total         Months
                               2009-01    2012-03
ABC              11            10      1
                               2011-01
DEF              29            29
                               2001-09   2008-01   2010-09
GHI              119           10        9         100

So far, I have only been able to get the first 2 columns of the desired result above by doing:

df1 <- ddply(resultSet, .(company_name), summarize, sum(as.numeric(total_count)))

But I am not sure how I can append information for individual months

  • 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-11T21:33:36+00:00Added an answer on June 11, 2026 at 9:33 pm
    library(reshape2)
    res <- ddply(resultSet, .(Company), summarize, Total = sum(Total_Count))
    # if value.var is not specified, dcast uses the last column. see ?guess_value
    months <- dcast(resultSet, Company ~ Month, value.var = "Total_Count", sum)
    join(res, months, by = "Company")
      Company Total 2001-09 2008-01 2009-01 2010-09 2011-01 2012-03
    1     ABC    11      NA      NA       1      NA      NA      10
    2     DEF    29      NA      NA      NA      NA      29      NA
    3     GHI   119      10       9      NA     100      NA      NA
    

    it was important in context of the question to have the aggregrate function.

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

Sidebar

Related Questions

My data frame looks like this TFexp ID Entrez_Gene_ID Symbol adj.P.Val P.Value t B
Suppose I have a data frame, df, that looks like: f t1 t2 t3
Suppose we create a data.frame like this: > hugs_per_day <- rnorm(10) > hugs_per_day <-
I need to create a data.frame that will be populated one row at a
I have a data frame like below (20,000 rows by 49 cols). Each row
I have a data frame with two qualitative variables (Q1, Q2) which are both
I have a data frame consisting of results from multiple runs of an experiment,
R: how can I populate the rows of a data frame, in which each
I have a data frame, say: df <- data.frame(a=1:10,b=runif(10)) I'd like to be able
I'm trying to normalize some data which I have in a data frame. I

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.