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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:39:00+00:00 2026-06-10T12:39:00+00:00

Possible Duplicate: Idiomatic R code for partitioning a vector by an index and performing

  • 0

Possible Duplicate:
Idiomatic R code for partitioning a vector by an index and performing an operation on that partition
How to calculate median of profits for a particular country

I am trying to find average of a column by using another column in R.It’s so easy to do it in SQL but not able to find proper functions and implement them.Here is some sample data as below.

data("Forbes2000", package = "HSAUR")
head(Forbes2000)

##    rank                name        country             category  sales profits  assets marketvalue
## 1    1           Citigroup  United States              Banking  94.71   17.85 1264.03      255.30
## 2    2    General Electric  United States        Conglomerates 134.19   15.59  626.93      328.54
## 3    3 American Intl Group  United States            Insurance  76.66    6.46  647.66      194.87
## 4    4          ExxonMobil  United States Oil & gas operations 222.88   20.96  166.99      277.02
## 5    5                  BP United Kingdom Oil & gas operations 232.57   10.27  177.57      173.54
## 6    6     Bank of America  United States              Banking  49.01   10.81  736.45      117.55
  • 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-10T12:39:01+00:00Added an answer on June 10, 2026 at 12:39 pm

    With a data.frame named dat that looked like:

         rank              name  country       category  sales profits assets marketvalue
    21     21   DaimlerChrysler Germany    Consumer_dur 157.13    5.12 195.58       47.43
    

    Try (untested d/t the numerous spaces in the text preventing read.table from making sense of it):

    aggregate(dat[ , c("sales", "profits", "assets", "marketvalue")],   # cols to aggregate
              dat["country"],                                           # group column
              FUN=mean)                          # aggregation function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Why is Java's Iterator not an Iterable? Idiomatic way to use for-each
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: How to do the vector of sets in C++? I want to
Possible Duplicate: Difference of create Index by using include column or not using Edit:
Possible Duplicate: How to successfully rewrite old mysql-php code with deprecated mysql_* functions? I
Possible Duplicate: Idiomatic object creation in ruby Sometimes it's useful to assign numerous of
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:

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.