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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:28:54+00:00 2026-06-04T12:28:54+00:00

Given the matrix structure(list(X1 = c(1L, 2L, 3L, 4L, 2L, 5L), X2 = c(2L,

  • 0

Given the matrix

structure(list(X1 = c(1L, 2L, 3L, 4L, 2L, 5L), X2 = c(2L, 3L, 
4L, 5L, 3L, 6L), X3 = c(3L, 4L, 4L, 5L, 3L, 2L), X4 = c(2L, 4L, 
6L, 5L, 3L, 8L), X5 = c(1L, 3L, 2L, 4L, 6L, 4L)), .Names = c("X1", 
"X2", "X3", "X4", "X5"), class = "data.frame", row.names = c(NA, 
-6L))

I want to create a 5 x 5 distance matrix with the ratio of matches and the total number of rows between all columns. For instance, the distance between X4 and X3 should be 0.5, given that both columns match 3 out of 6 times.

I have tried using dist(test, method="simple matching") from package “proxy” but this method only works for binary data.

  • 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-04T12:28:56+00:00Added an answer on June 4, 2026 at 12:28 pm

    Using outer (again 🙂

    my.dist <- function(x) {
     n <- nrow(x)
     d <- outer(seq.int(ncol(x)), seq.int(ncol(x)),
                Vectorize(function(i,j)sum(x[[i]] == x[[j]]) / n))
     rownames(d) <- names(x)
     colnames(d) <- names(x)
     return(d)
    }
    
    my.dist(x)
    #           X1        X2  X3  X4        X5
    # X1 1.0000000 0.0000000 0.0 0.0 0.3333333
    # X2 0.0000000 1.0000000 0.5 0.5 0.1666667
    # X3 0.0000000 0.5000000 1.0 0.5 0.0000000
    # X4 0.0000000 0.5000000 0.5 1.0 0.0000000
    # X5 0.3333333 0.1666667 0.0 0.0 1.0000000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a matrix data structure in C. I have a struct
I need to create a function to rotate a given matrix (list of lists)
If I have a matrix given as a list of rows [[1,2,3],[4,5,6]], I want
I have a function that returns a comparison matrix from a given list: def
I want to do a function that given 2 matrix returns the sum of
How can I evaluate a string of class character as data frame? Concretely, I
Given: square matrix, and list which represents the index of rows to be removed,
I'm considering graph data structure implementations and am looking at the incidence list representation.
Given a matrix of size M and N , we want to fill in
Given an n-dimensional matrix of values: what is the most efficient way of retrieving

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.