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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:40:01+00:00 2026-05-23T23:40:01+00:00

My input is df1 <- data.frame(Row=c(row1, row2, row3, row4, row5), A=c(1,2,3,5.5,5), B=c(2,2,2,2,0.5), C= c(1.5,0,0,2.1,3))

  • 0

My input is

 df1 <- data.frame(Row=c("row1", "row2", "row3", "row4", "row5"),
                   A=c(1,2,3,5.5,5), 
                   B=c(2,2,2,2,0.5),
                   C= c(1.5,0,0,2.1,3))

It look like this:

#  Row1 1   2   1.5
#  Row2 2   2   0
#  Row3 3   2   0
#  Row4 5.5 2   2.1
#  Row5 5   0.5 3

I want to get the sum of all these pairs of rows, with the following equation. Let’s said for Row1 and Row2 pairs: I want to multiply each column’s entry and sum them into one final answer, for example-

  • Row1-Row2 answer is (1*2) + (2*2)+ (1.5 *0) = 6
  • Row1-Row3 answer is (1*3) + (2*2) + (1.5*0) = 7

I want to do all analysis for each pairs of row and get a result data frame like this:

row1    row2    6
row1    row3    7
row1    row4    12.65
row1    row5    10.5
row2    row3    10
row2    row4    15
row2    row5    11
row3    row4    20.5
row3    row5    16
row4    row5    34.8

How can I do this with R? Thanks a lot for comments.

  • 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-23T23:40:02+00:00Added an answer on May 23, 2026 at 11:40 pm
    1. Create all the combinations you need with combn. t is used to transpose the matrix as you expect it to be formatted.
    2. Use apply to iterate over the indices created in step 1. Note that we use negative indexing so we don’t try to sum the Row column.
    3. Bind the two results together.

    `

    ind <- t(combn(nrow(df1),2))
    out <- apply(ind, 1, function(x) sum(df1[x[1], -1] * df1[x[2], -1]))
    cbind(ind, out)
    
               out
    [1,] 1 2  6.00
    [2,] 1 3  7.00
    [3,] 1 4 12.65
     .....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a input dataframe like this (the real one is very large, so
input is like this 5 // is # of vertices 1 1 0 1
Input string is something like this: OU=TEST:This001. We need extra This001. Best in C#.
Input XML: <Data> <BPP> <CP>A</CP> <Name>Joe</Name> </BPP> <BPP> <CP>A</CP> <Name>Show</Name> </BPP> <BPP> <CP>B</CP> <Name>Cunny</Name>
Input data: rules = ( (1|1: A), (2|1: B), (3|1: C), (2|2: X) )
input: position fst 1 0.6 2 0.8 3 0.9 4 0.3 5 1 This
Input string was not in a correct format. At this line: int total =
Given input like <a> <b> <c>everything below</c> <d></d> </b> <b> <c>everything below</c> <d></d> </b>
Input: The customer claims that the application (.NET) when querying for some data returns
Input ID RowID Data 1 1 S 1 1 Q 1 1 L 1

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.