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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:13:53+00:00 2026-06-04T17:13:53+00:00

Consider the following matrix: sequence <- structure(list(C1 = c(2L, 9L, 3L, 9L, 1L, 8L,

  • 0

Consider the following matrix:

sequence <- structure(list(C1 = c(2L, 9L, 3L, 9L, 1L, 8L, 9L, 6L, 4L, 5L, 
3L, 2L), C2 = c(3L, 6L, 5L, 8L, 8L, 7L, 3L, 7L, 2L, 1L, 4L, 1L
), C3 = c(8L, 2L, 6L, 4L, 6L, 5L, 7L, 4L, 5L, 9L, 1L, 7L)), .Names = c("C1", 
"C2", "C3"), class = "data.frame", row.names = c(NA, -12L))

Each row has a combination of 3 numbers. I’m trying to recombine all the triads into pairs, with each triad row being divided into three rows (each containing a possible pair). For example, row 1 (2, 3, 8) should be transformed into row 1 (2, 3), row 2 (3, 8) and row 3 (2, 8). The result should look like this:

result <- structure(list(Col1 = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 
3L, 3L), .Label = c("Row 1", "Row 2", "Row 3"), class = "factor"), 
    Col2 = c(2L, 3L, 2L, 9L, 6L, 9L, 3L, 5L, 3L), Col3 = c(3L, 
    8L, 8L, 6L, 2L, 2L, 5L, 6L, 6L)), .Names = c("Col1", "Col2", 
"Col3"), class = "data.frame", row.names = c(NA, -9L))

(the table repeats until all rows are recombined)

I’ve tried to do this with combn function: t(combn(unlist(t(sequence)),2)) but this is recombining all elements of the matrix amongst themselves, rather than recombining only the elements of each row. Any light?

  • 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-04T17:13:55+00:00Added an answer on June 4, 2026 at 5:13 pm

    I’m sure there’s a much cleaner way but you could just use cbind to get the pairs of interest three times, then use rbind to put them together.

    sequence <- structure(list(C1 = c(2L, 9L, 3L, 9L, 1L, 8L, 9L, 6L, 4L, 5L, 
    3L, 2L), C2 = c(3L, 6L, 5L, 8L, 8L, 7L, 3L, 7L, 2L, 1L, 4L, 1L
    ), C3 = c(8L, 2L, 6L, 4L, 6L, 5L, 7L, 4L, 5L, 9L, 1L, 7L)), .Names = c("C1", 
    "C2", "C3"), class = "data.frame", row.names = c(NA, -12L))
    
    # Essentially what you wanted
    temp.result <- with(sequence, rbind(cbind(C1, C2), cbind(C2, C3), cbind(C1, C3)))
    # Identify which rows we're talking about
    id <- rep(seq(nrow(sequence)), 3)
    # Put it all together
    result <- cbind(id, temp.result)
    # Order it the way you imply in your question
    result <- result[order(result[,1]),]
    # Give it the colnames you want
    colnames(result) <- c("Col1", "Col2", "Col3")
    head(result)
    #     Col1 Col2 Col3
    #[1,]    1    2    3
    #[2,]    1    3    8
    #[3,]    1    2    8
    #[4,]    2    9    6
    #[5,]    2    6    2
    #[6,]    2    9    2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following scenario: I have RESTful URL /articles that returns list of articles user
Let's consider following, simplified example: We have 2 tabs withing <rich:tabPanel switchType=ajax> , each
Consider the following code: require(Hmisc) num.boots <- 10 data <- rchisq(500, df = 5)
Consider following example: class CBase abstract { protected: CBase() { } }; I could
Consider following XAML: <Window x:Class=WpfApplication1.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=350 Width=525> <StackPanel> <TextBlock Text={Binding Dic[foo]}
Consider the following matrix, m <- matrix(letters[c(1,2,NA,3,NA,4,5,6,7,8)], 2, byrow=TRUE) ## [,1] [,2] [,3] [,4]
Consider the following data source: declare @Test table (EmpId int, ProdId int, Sold int)
Consider following simple DAO example: public abstract class DAOFactory { public abstract AccountDAO getAccountDAO();
Consider following class class test { public: test(int x){ cout<< test \n; } };
Consider following tables structure: users (user_id, ...) images (image_id, user_id, ...) tag_links (tag_id, image_id)

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.