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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:20:22+00:00 2026-06-13T23:20:22+00:00

I have a vector that I have created from grouped data: sitesMODE FT KM

  • 0

I have a vector that I have created from grouped data:

sitesMODE
FT         KM         KO         LN         LY 
16.840000  32.230769   8.846154 237.000000  57.923077

I want to find the difference of each value to every value and ULTIMATELY report it in a single object or column so that I can plot it.

I will reproduce the data here(albeit in matrix form):

siteMODE <- matrix(c(16.84, 32.23, 8.84, 237.00, 57.92), 1, 5, byrow = TRUE)
colnames(siteMODE) <- c("FT", "KM", "KO", "LN", "LY")

I know that I can use:

diffMODELY <- abs(siteMODE - siteMODE[[5]])

to find the difference between the expressed column/element [[n]] so that:

diffMODELY 
FT        KM        KO        LN        LY 
41.08308  25.69231  49.07692 179.07692   0.00000 

My question is now, how can I do this without having to create an object like diffMODELY for every column’s/element’s difference? AND how can I report the results into as a single object or column in a matrix?

  • 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-13T23:20:22+00:00Added an answer on June 13, 2026 at 11:20 pm

    Looking for something like this?

    DIFF <- sapply(1:ncol(siteMODE), function(i) abs(siteMODE - siteMODE[i]))
    DIFF[upper.tri(DIFF)]
     [1]  15.39   8.00  23.39 220.16 204.77 228.16  41.08  25.69  49.08 179.08
    

    The sapply part computes the differences you want, but it gives you a matrix, since you want the resulting differences into a vector you may want to chose either the upper triangular matrix elements or the lower ones, that’s why I applied upper.tri function to select just the upper triangular elements and the final result is a vector.

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

Sidebar

Related Questions

I am trying to get JSON data from a string that I have created
I have one vector v, created with c(), that has this data: v[a,b,d,z,e,f], it
I have a vector that I want to use to create a heap. I'm
I have a std::vector. I want to create iterators representing a slice of that
I have a vector X that contains positive numbers that I want to bin/discretize.
I have a vector of beans that holds information I want to display in
If I have a for loop that reads from a data file and each
I have a 1 megabyte vector svg file that I created with Adobe Illustrator.
I'm trying to create a vector of custom items that I have created but
I have a function that creates a 2D vector void generate(int n) { vector<

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.