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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:27:05+00:00 2026-06-08T07:27:05+00:00

for a data frame as follow id<-c(1,1,2,3,3,2) p<-c(10,0,22,34,0,0) df<-data.frame(id,p) I need a summary table

  • 0

for a data frame as follow

id<-c(1,1,2,3,3,2)
p<-c(10,0,22,34,0,0)
df<-data.frame(id,p)

I need a summary table like

id   p
1    10
2    22
3    34

which is actually aggregated summation of p for each id.
can I get this with ‘dcast’?

  • 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-08T07:27:12+00:00Added an answer on June 8, 2026 at 7:27 am

    Why do you need dcast? Try aggregate in base R:

    df <- data.frame(id = c(1,1,2,3,3,2),
                     p = c(10,0,22,34,0,0))
    aggregate(df, by=list(id), sum)
    #   Group.1 id  p
    # 1       1  2 10
    # 2       2  4 22
    # 3       3  6 34
    

    You can also trick dcast as below. Your data is not quite in the expected “molten” form for dcast:

    library(reshape2)
    dcast(df, id ~ ., value.var = "p", sum)
    #   id NA
    # 1  1 10
    # 2  2 22
    # 3  3 34
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data frame like below (20,000 rows by 49 cols). Each row
I have a data frame in which each column is a time series of
In a data.frame (or data.table ), I would like to "fill forward" NAs with
I have a data frame with two qualitative variables (Q1, Q2) which are both
I have extracted data to a data frame with mixed format dates that need
How can I order the levels of a factor in one data.frame column according
I have the following data frame in R which gives me the customers 1,2,
I occasionally need to extract specific rows from a data.frame based on values from
It seems like melt will reshape your data frame with id columns and stacked
I have a data frame that's about ts1[100, 2000] in dimension as follows: >

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.