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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:14:24+00:00 2026-06-09T19:14:24+00:00

I am comparing a bunch of baseline and end-of-study differences across groups. For examples,

  • 0

I am comparing a bunch of baseline and end-of-study differences across groups. For examples, I may have the following data set:

> baseline.comp
                             cluster 1970_pred 2008_pred  ratio   diff
 9  Many Transitions, Middle Income    0.1156    0.0248 4.6613 0.0908
10     Many Transitions, Low Income    0.1779    0.0389 4.5733 0.1390
 4       Dictatorships, High Income    0.1403    0.0307 4.5700 0.1096
 7    One Transition, Middle Income    0.0801    0.0219 3.6575 0.0582
 1         Democracies, High Income    0.0396    0.0116 3.4138 0.0280
 5     Dictatorships, Middle Income    0.1252    0.0399 3.1378 0.0853
 2       Democracies, Middle Income    0.0811    0.0291 2.7869 0.0520
 8       One Transition, Low Income    0.1912    0.0775 2.4671 0.1137
 3          Democracies, Low Income    0.1612    0.0698 2.3095 0.0914
 6        Dictatorships, Low Income    0.1854    0.0821 2.2582 0.1033

In this example, I would like to compare the column pred_1970 with itself so that I could have a table telling me about the differences in baseline conditions across these clusters. It would a 10 by 10 table but only the bellow diagonal cells would have actuall numbers, reflecting the differences in the initial conditions for these groups. I was wondering if R already has some implemented functionally to do that.

Thank you,

Antonio Pedro

  • 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-09T19:14:25+00:00Added an answer on June 9, 2026 at 7:14 pm

    outer is what you are looking for.

    baseline_diff <- outer(baseline.comp[['1970_pred']],baseline.comp[['1970_pred']], '-')
    ## if you want to set the dimension names (but they will be very long!)
    # dimnames(baseline_diff) <- list(baseline.comp[['cluster']],
    #                                  baseline.comp[['cluster']])
     baseline_diff
              [,1]    [,2]    [,3]    [,4]   [,5]    [,6]    [,7]    [,8]    [,9]   [,10]
     [1,]  0.0000 -0.0623 -0.0247  0.0355 0.0760 -0.0096  0.0345 -0.0756 -0.0456 -0.0698
     [2,]  0.0623  0.0000  0.0376  0.0978 0.1383  0.0527  0.0968 -0.0133  0.0167 -0.0075
     [3,]  0.0247 -0.0376  0.0000  0.0602 0.1007  0.0151  0.0592 -0.0509 -0.0209 -0.0451
     [4,] -0.0355 -0.0978 -0.0602  0.0000 0.0405 -0.0451 -0.0010 -0.1111 -0.0811 -0.1053
     [5,] -0.0760 -0.1383 -0.1007 -0.0405 0.0000 -0.0856 -0.0415 -0.1516 -0.1216 -0.1458
     [6,]  0.0096 -0.0527 -0.0151  0.0451 0.0856  0.0000  0.0441 -0.0660 -0.0360 -0.0602
     [7,] -0.0345 -0.0968 -0.0592  0.0010 0.0415 -0.0441  0.0000 -0.1101 -0.0801 -0.1043
     [8,]  0.0756  0.0133  0.0509  0.1111 0.1516  0.0660  0.1101  0.0000  0.0300  0.0058
     [9,]  0.0456 -0.0167  0.0209  0.0811 0.1216  0.0360  0.0801 -0.0300  0.0000 -0.0242
    [10,]  0.0698  0.0075  0.0451  0.1053 0.1458  0.0602  0.1043 -0.0058  0.0242  0.0000
    

    To display only the lower (or upper) triangle use tril or triu in the Matrix package

    library(Matrix)
    
    tril(baseline_diff)
    
    10 x 10 Matrix of class "dtrMatrix"
          [,1]    [,2]    [,3]    [,4]    [,5]    [,6]    [,7]    [,8]    [,9]    [,10]  
     [1,]  0.0000       .       .       .       .       .       .       .       .       .
     [2,]  0.0623  0.0000       .       .       .       .       .       .       .       .
     [3,]  0.0247 -0.0376  0.0000       .       .       .       .       .       .       .
     [4,] -0.0355 -0.0978 -0.0602  0.0000       .       .       .       .       .       .
     [5,] -0.0760 -0.1383 -0.1007 -0.0405  0.0000       .       .       .       .       .
     [6,]  0.0096 -0.0527 -0.0151  0.0451  0.0856  0.0000       .       .       .       .
     [7,] -0.0345 -0.0968 -0.0592  0.0010  0.0415 -0.0441  0.0000       .       .       .
     [8,]  0.0756  0.0133  0.0509  0.1111  0.1516  0.0660  0.1101  0.0000       .       .
     [9,]  0.0456 -0.0167  0.0209  0.0811  0.1216  0.0360  0.0801 -0.0300  0.0000       .
    [10,]  0.0698  0.0075  0.0451  0.1053  0.1458  0.0602  0.1043 -0.0058  0.0242  0.0000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of input text boxes that have the attribute ORIGINAL set
I have a bunch of files (almost 100) which contain data of the format:
The program outputs a bunch of nulls when comparing. I think I am not
I have a bunch of images to download, after their downloaded I'd like to
In C# I have a bunch of objects all inheriting from the same base
I have two objects (instances of the same class) with a bunch of properties,
After compiling some code, the compiler generates a bunch of files. I have statistics,
I have a LabVIEW application that I inherited that has a bunch of sub-VIs.
There's got to be a better way! I have a bunch of log records
Hello computing peoples of the world! I have a bunch of .mm with their

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.