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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:34:26+00:00 2026-05-21T04:34:26+00:00

Currently I do the following: x <- cbind(c(1, 2, 3), c(4, 5, 6)) x.merged

  • 0

Currently I do the following:

x <- cbind(c(1, 2, 3), c(4, 5, 6))
x.merged <- matrix(t(x), ncol=1)

to create one column with values 1, 4, 2, 5, 3, 6, from the matrix x. But relying on t(x) seems a bit clunky. Is there a better way to do this? I’d like to avoid a for-loop or apply if there’s a simpler built-in function that handles this sort of thing.

EDIT: To be clearer, x is just given to me. The first line of code above was only meant to illustrate the values involved. It might have been better for me to write:

> x
     [,1] [,2]
[1,]    1    4
[2,]    2    5
[3,]    3    6
  • 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-21T04:34:27+00:00Added an answer on May 21, 2026 at 4:34 am

    Actually, if you make it a vector it doesn’t take more than :

    > c(t(x))
    [1] 1 4 2 5 3 6
    

    Or, if you really have to avoid t() then you could do :

    > c(apply(x,2,rbind))
    [1] 1 4 2 5 3 6
    

    This works for an arbitrary number of columns, but includes an apply. If you don’t want to use that one, you’ll have to manually specify all the columns you want to paste behind eachother. But the t() solution is by far the fastest :

    > n <- 10000000    
    > x <- matrix(rnorm(n),ncol=2)
    > system.time(c(t(x)))
       user  system elapsed 
       0.07    0.00    0.06 
    
    > system.time(c(rbind(x[,1],x[,2])))
       user  system elapsed 
       0.22    0.05    0.26 
    

    Remember that a matrix can be seen as a vector with dimensions added to it, and is always read columnwise. So you cannot really avoid the t() in your solution. You could always just use it as a vector, eg :

    > x[4]
    [1] 4
    

    just works, as long as you remember that the matrix is read columnwise. So in your case you’ll need

    > t(x)[4]
    [1] 5
    

    In case you really need it as a matrix, then :

    > matrix(t(x))
         [,1]
    [1,]    1
    [2,]    4
    [3,]    2
    [4,]    5
    [5,]    3
    [6,]    6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently following a tutorial in a book, and it instructs to create a
I have currently the following setup: An object graph of all requests read from
I am trying to create an SQL database in Android. I am currently following
I am currently following tutorials on viewing data from the database using the Framework
im just getting started on maven, and im currently following the article from http://www.sonatype.com/books/mvnex-book/reference/simple-project-sect-create-simple.html
I'm currently following the great tutorial on Geekpedia to create my own Chat Client
I'm currently following a tutorial on modern OpenGL. I copied a code from the
Currently following is the setup of my wifi connection. Laptop 1 ------> Wifi Router
I'm currently following the third tutorial listed here: here where I'm trying to compile
I'm currently following: http://railsontherun.com/2007/10/04/sexy-charts-in-less-than-5-minutes/ I went through it all pretty easily, but then when

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.