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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:50:07+00:00 2026-06-17T20:50:07+00:00

I am wondering what would be the best way to add, for example, columns

  • 0

I am wondering what would be the best way to add, for example, columns of quantiles to the dataset. I was thinking to use ave() function for that, something like ave(iris$Sepal.Length, iris$Species, FUN=quantile) – but in this case ave() merges values returned by quantile() (which in this case returns 5 values per subset) and cut them for the length of iris…

Thanks in advance for suggestions!

  • 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-17T20:50:08+00:00Added an answer on June 17, 2026 at 8:50 pm

    There are a lot of SO questions on this general topic, recommending various uses of ave(), aggregate(), plyr(), reshape2::cast, or data.table depending on personal preference, readability, compactness, flexibility, speed … Here’s a simple solution with aggregate() that seems to do what you want:

    (aa <- aggregate(Sepal.Length~Species,data=iris,quantile))
    
    ##      Species Sepal.Length.0% Sepal.Length.25% Sepal.Length.50% Sepal.Length.75%
    ## 1     setosa           4.300            4.800            5.000            5.200
    ## 2 versicolor           4.900            5.600            5.900            6.300
    ## 3  virginica           4.900            6.225            6.500            6.900
    ##   Sepal.Length.100%
    ## 1             5.800
    ## 2             7.000
    ## 3             7.900
    

    edit: re-reading/based on comment, this is not what you want: you need the summarized values replicated for each row, not just once per group.

    Perhaps

    merge(iris,aa,by="Species")
    

    although that gives a slightly weird data frame (the last “column” is actually a matrix).

    It’s a little bit magical, but

    merge(iris,with(aa,data.frame(Species,Sepal.Length)))
    

    is better — it unpacks the weird data frame returned by aggregate() a bit more (the names are still a bit wonky).

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

Sidebar

Related Questions

I'm just wondering, as a hypothetical example, what would be the best way to
I was wondering what would be the best way to add color to each
i was wondering what would be the best way to code a browser plugin
I recently started learning backbone and was wondering what would be the best way
I was wondering, what would be the best way to validate an integer. I'd
I've been wondering what the best way to do this would be. I've got
Wondering what the best / good way of doing this would be in jQuery.
Hey im just wondering what would be the best collection to use when creating
I was just wondering what would be the best way of storing user-specific settings
I was wondering what would be the best way to handle errors in an

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.