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

  • Home
  • SEARCH
  • 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 5984051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:19:08+00:00 2026-05-22T22:19:08+00:00

i have a bunch of data collection , example : 1.00 3 4 1.00

  • 0

i have a bunch of data collection , example :

 1.00 3 4
 1.00 0 1
 51.00 1 4
 84.00 3 4
 95.00 0 2
 110.00 2 4
 120.00 0 1
 121.00 1 2
 124.00 2 4
 158.00 3 4
 159.00 1 3
 172.00 0 4
 214.00 0 4
 223.00 2 4
 224.00 1 2
 228.00 1 4
 229.00 0 1
 232.00 2 3
 233.00 3 4
 233.00 1 3
 246.00 0 2
 292.00 0 3
 294.00 0 4
 294.00 2 4
 294.00 3 4
 318.00 1 2
 331.00 0 1
 383.00 2 4
 402.00 3 4

then the output that i want to generate is like this :

node_src node_dst time_repeated time1 time2 ... average_time ß 

detail :

*node_src = 2nd column 
*node_dst = 3rd column 
*time_repeated = the number of the same line is repeated, example 3 4 is repeated 5 time
*time1, time2 .. = are the value of column 1
*average_time = the average time for the different interval, 
 example see below,
*ß = time_repeated / average_time

my attempt generated this result :

node1  node2  nbrepeated    time1  time2  time3  time4  time5  time6  time7  average ß  
2       4       6           110.0  124.0  223.0  294.0  383.0  461.0  543.0  6.0     0           
2       3       1           232.0  402.0  0.0    0.0    0.0    0.0    0.0    1.0     0     
1       3       2           159.0  233.0  521.0  0.0    0.0    0.0    0.0    2.0     4      
1       2       4           121.0  224.0  318.0  461.0  573.0  0.0    0.0    4.0     5     
0       4       4           172.0  214.0  294.0  415.0  543.0  0.0    0.0    4.0     5      
0       2       5           95.0   246.0  415.0  536.0  572.0  588.0  0.0    5.0     :      
0       3       3           292.0  403.0  455.0  588.0  0.0    0.0    0.0    3.0     :      
1       4       2           51.0   228.0  494.0  0.0    0.0    0.0    0.0    2.0     :      
0       1       4           1.0    120.0  229.0  331.0  536.0  0.0    0.0    4.0     :      
3       4       6           1.0    84.0   158.0  233.0  294.0  402.0  431.0  6.0     :

i was unable to fine the average time and ß due to the complexity of the calculation
to find the average time is like this :

    121.0  224.0  318.0  461.0  573.0 

    avg_time = ((224-121)+(318-224)+(461-318)+(573-461))/4

the challenge here, is to make it dynamically, since the number time field is unknown…
made using bash…

here is the code, thanks to glenn jackman

 #!/bin/bash


declare -A t

while read tm f1 f2; do
    t["$f1:$f2"]+=" $tm"
done < $1

max=0
for key in "${!t[@]}"; do
    set -- ${t[$key]}
    [[ $# -gt $max ]] && max=$#
done

{
    printf "field1 field2 nbrepeated"
    for i in $(seq $max); do printf " %s" time$i; done
    echo " average_time beta"


    for key in "${!t[@]}"; do
        f1=${key%:*}
        f2=${key#*:}
        set -- ${t[$key]}
        f3=$(($# - 1))
        f4=$(($# - 1))
    f5= 1 
        printf "%d %d %d" $f1 $f2 $f3 
        for i in $(seq $max); do
            printf " %.1f" ${1-0}  
            shift
            done
        printf " %.1f %.1f" $f4 $f5


        echo ""

    done
} | column -t

modification need to do :

  1. find the average time : avg_time
  2. find the beta

p/s : normally to find the average time, people do : sum/NR, but it was not the case for my question

case solve : here is the output

field1  field2  nbrepeated  time1  time2  time3  time4  time5  time6  time7  average_time  beta
2       4       6           110.0  124.0  223.0  294.0  383.0  461.0  543.0  72.16         0.08
2       3       1           232.0  402.0  0.0    0.0    0.0    0.0    0.0    170.00        0.00
1       3       2           159.0  233.0  521.0  0.0    0.0    0.0    0.0    181.00        0.01
1       2       4           121.0  224.0  318.0  461.0  573.0  0.0    0.0    113.00        0.03
  • 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-05-22T22:19:09+00:00Added an answer on May 22, 2026 at 10:19 pm

    First, note that the average formula can be simplified. For example:

    121.0  224.0  318.0  461.0  573.0 
    = (573.0 - 121.0)/4
    

    I have added the following section to calculate the average and beta:

    avg=0
    beta=0
    if [ $f3 -ne 0 ]
    then
       total=$(bc<<<${@: -1}-$1)
       avg=$(bc<<<"scale=2;$total/$f3")
       beta=$(bc<<<"scale=2;$f3/$avg")
    fi 
    

    The complete script becomes:

    declare -A t
    
    while read tm f1 f2; do
        t["$f1:$f2"]+=" $tm"
    done < f.txt
    
    max=0
    for key in "${!t[@]}"; do
        set -- ${t[$key]}
        [[ $# -gt $max ]] && max=$#
    done
    
    {
        printf "field1 field2 nbrepeated"
        for i in $(seq $max); do printf " %s" time$i; done
        echo " average_time beta"
    
    
        for key in "${!t[@]}"; do
            f1=${key%:*}
            f2=${key#*:}
            set -- ${t[$key]}
        f3=$(($# - 1))
    
        avg=0
        beta=0
            # don't want to divide by zero if we have only one time 
        if [ $f3 -ne 0 ]
        then
           total=$(bc<<<${@: -1}-$1)
           avg=$(bc<<<"scale=2;$total/$f3")
           beta=$(bc<<<"scale=2;$f3/$avg")
        fi 
    
            printf "%d %d %d" $f1 $f2 $f3 
            for i in $(seq $max); do
                printf " %.1f" ${1-0}  
                shift
            done
    
        printf " %.2f %.2f" $avg $beta
    
    
            echo ""
    
        done
    } | column -t
    

    Output

    field1  field2  nbrepeated  time1  time2  time3  time4  time5  time6  average_time  beta
    2       4       4           110.0  124.0  223.0  294.0  383.0  0.0    68.25         0.05
    2       3       0           232.0  0.0    0.0    0.0    0.0    0.0    0.00          0.00
    1       3       1           159.0  233.0  0.0    0.0    0.0    0.0    74.00         0.01
    1       2       2           121.0  224.0  318.0  0.0    0.0    0.0    98.50         0.02
    0       4       2           172.0  214.0  294.0  0.0    0.0    0.0    61.00         0.03
    0       2       1           95.0   246.0  0.0    0.0    0.0    0.0    151.00        0.00
    0       3       0           292.0  0.0    0.0    0.0    0.0    0.0    0.00          0.00
    1       4       1           51.0   228.0  0.0    0.0    0.0    0.0    177.00        0.00
    0       1       3           1.0    120.0  229.0  331.0  0.0    0.0    110.00        0.02
    3       4       5           1.0    84.0   158.0  233.0  294.0  402.0  80.20         0.06
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a bunch of data on S3 (images) but just started reading about
I have to copy a bunch of data from one database table into another.
I have a bunch of overloaded functions that operate on certain data types such
I have a php array that has a bunch of data that I need
Say you have a bunch of files. Say you can store meta data to
I have just scraped a bunch of Google Buzz data, and I want to
I have a data warehouse containing typical star schemas, and a whole bunch of
I have a .net assembly that contains data access code (a bunch of Typed
I have a bunch of data that I'm pulling into my application which frankly
I have a bunch of controller actions mostly used for saving data to backend

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.