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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:38:28+00:00 2026-06-18T14:38:28+00:00

I have a data.frame for aggregation which is simply done by ddply from plyr.

  • 0

I have a data.frame for aggregation which is simply done by ddply from plyr. The target now is to write a function that bind the aggregation object automatically to the original data. The problem is, that there can be more then one aggregation variable.

The following refers to an example with only one aggregation variable:

Here the dataframe I have:

  M O
1 1 6 
2 2 7 
3 2 4 
4 1 6 

Then with ddply I get the aggregation for “O”:

TEST <- ddply(.data = DF,
              .variables = c("M"),
              .fun = summarise,
              NEW = sum(O))

The result looks like:

  M NEW
1 1  12
2 2  11

What I wanna do now is to write a function that enables me to bind the variable “New” to the original data.frame.

In a loop it works with:

for(i in 1:nrow(TEST)) {
  DF$New[DF$M == TEST$M[i]] <- TEST$NEW[i]
  } 

  M O New
1 1 6  12 
2 2 7  11 
3 2 4  11 
4 1 6  12 

Now I wanna transform this into a function that gives an equivalent output even when there are more then just one aggregation variable.

  • 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-18T14:38:30+00:00Added an answer on June 18, 2026 at 2:38 pm

    Like I said in my comment:

    ddply(.data = DF,
          .variables = c("M"),
          .fun = transform,
           NEW = sum(O))
      M O NEW
    1 1 6  12
    2 1 6  12
    3 2 7  11
    4 2 4  11
    
    • 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 which I would like to write it to a
I have a data frame with two qualitative variables (Q1, Q2) which are both
I have a data frame that is some 35,000 rows, by 7 columns. it
I have a data frame consisting of results from multiple runs of an experiment,
I have a data frame that's about ts1[100, 2000] in dimension as follows: >
I have this data.frame : df <- read.table(text= section to from time a 1
I have a dataframe that holds data at a particular level of aggregation -
I have the following question: I have data frame which looks like this. I
I have a data.frame in which certain variables contain a text string. I wish
I have a data.frame in which each gene name is repeated and contains values

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.