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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:57:04+00:00 2026-06-09T12:57:04+00:00

I have the following problem: I have the following table: > data StartPoint EndPoint

  • 0

I have the following problem: I have the following table:

> data
    StartPoint EndPoint timeDiff
1         A91    TX043      258
2         A91    TX048      547
3         A92    TX088      330
4         A91    TX088      289
5         A91    TX043      387
6         A92    TX088      241
7         A91    TX088      213
8         A92    TX043      295
9         A91    TX088      518
10        A92    TX088      414

I would need an aggregation of the following form:

StartPoint  EndPoint  count  mean(timeDiff)
   A91         TX088    3    mean of 289,213 and 518
   A91         TX043    2    mean of 258 and 387
   A91         TX048    1     547
   A92         TX088    3    mean of 330, 241 and 414
   A92         TX043    1     295

count is the number of occurences of same StartPoint and EndPoint pair and mean is the average of the timeDiff of the entries with same StartPoint and EndPoint pair. The result should be sorted on StartPoint, count and EndPoint.

Any help would be greatly appreciated.

Thanks in advance,
Sugi

my data:

data <- structure(list(StartPoint = c("A91", "A91", "A92", "A91", "A91", "A92", "A91", "A92", "A91", "A92"), EndPoint = c("TX043", "TX048", "TX088", "TX088", "TX043", "TX088", "TX088", "TX043", "TX088", "TX088"), timeDiff = c(258, 547, 330, 289, 387, 241, 213, 295, 518, 414)), .Names = c("StartPoint", "EndPoint", "timeDiff"), row.names = c(NA, 10L), class = "data.frame")
  • 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-09T12:57:05+00:00Added an answer on June 9, 2026 at 12:57 pm

    You can do this with the base function aggregate:

    aggregate(timeDiff~StartPoint+EndPoint,data,function(x) cbind(length(x),mean(x)))
      StartPoint EndPoint timeDiff.1 timeDiff.2
    1        A91    TX043     2.0000   322.5000
    2        A92    TX043     1.0000   295.0000
    3        A91    TX048     1.0000   547.0000
    4        A91    TX088     3.0000   340.0000
    5        A92    TX088     3.0000   328.3333
    

    But the ddply in the plyr package might give more pleasing results:

    library(plyr)
    ddply(data,c(.(StartPoint),.(EndPoint)),summarise,count=length(timeDiff),mean=mean(timeDiff))
      StartPoint EndPoint count     mean
    1        A91    TX043     2 322.5000
    2        A91    TX048     1 547.0000
    3        A91    TX088     3 340.0000
    4        A92    TX043     1 295.0000
    5        A92    TX088     3 328.3333
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem: my table is big enought (millions of data rows),
So im having a problem (obviously). I have the following MySQL table data 7
Folks, we have the following problem: we've got several objects containing table data that
I have following problem: I want to count data in one table, count data
I have the following problem. I have a table with a few hundred thousand
Greeting! I have the following problem. I have a table with huge number of
I'm new to wicket and stuck with the following problem: I have a table
The problem is the following, I have a table of friendships in my database,
I have the following problem: I select data from a DB, and for each
I have the following matching problem: I have two data.frames, one with an observation

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.