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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:24:52+00:00 2026-06-04T06:24:52+00:00

How can I apply different aggregate functions to different columns in R? The aggregate()

  • 0

How can I apply different aggregate functions to different columns in R? The aggregate() function only offers one function argument to be passed:

V1  V2        V3
1   18.45022  62.24411694
2   90.34637  20.86505214
1   50.77358  27.30074987
2   52.95872  30.26189013
1   61.36935  26.90993530
2   49.31730  70.60387016
1   43.64142  87.64433517
2   36.19730  83.47232907
1   91.51753  0.03056485
... ...       ...

> aggregate(sample,by=sample["V1"],FUN=sum)
  V1 V1       V2       V3
1  1 10 578.5299 489.5307
2  2 20 575.2294 527.2222

How can I apply a different function to each column, i.e. aggregate V2 with the mean() function and V2 with the sum() function, without calling aggregate() multiple times?

  • 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-04T06:24:53+00:00Added an answer on June 4, 2026 at 6:24 am

    For that task, I will use ddply in plyr

    > library(plyr)
    > ddply(sample, .(V1), summarize, V2 = sum(V2), V3 = mean(V3))
      V1       V2       V3
    1  1 578.5299 48.95307
    2  2 575.2294 52.72222
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My system is base on driving permit application. Where users can apply for different
I can always nest a div inside of a div and apply different backgrounds
Is it possible to have different classes for each simple_form so you can apply
I want to create a style which I can apply to different control types.
I want to apply different css on different browsers. I want to run one
In SQL Server, you can apply the use function to point a query to
I understand I can apply several options to the ServiceContract (like Name , Namespace
Is there a way I can apply '+ to '( 1 2 3)? edit:
here i need a batch file which can apply and create label or base
In a Zend view I can apply a partial template to an iterable element

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.