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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:06:46+00:00 2026-06-14T18:06:46+00:00

I’m using cbind to bring together a matrix of string and numerics, and it

  • 0

I’m using cbind to bring together a matrix of string and numerics, and it is returning all of the columns of numerics (except the first one) as NULL. Here is sample code:

nums <- matrix(data=c(1,2,3,4),ncol=2)
strs <- list()
strs[1] <- 'row1'
strs[2] <- 'row2'
result <- cbind(strs,nums)

> result
     strs         
[1,] "row1" 1 NULL
[2,] "row2" 2 NULL

I’m obviously overlooking something simple. Thanks for the help,

  • 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-14T18:06:47+00:00Added an answer on June 14, 2026 at 6:06 pm

    In this case, I think you’re going about the problem in slightly the wrong way. cbind returns a matrix. One of the limitations of matrices is that all elements must be of the same type. This means your c(1, 2, 3, 4) will, when coerced into a matrix, become the highest level data type present (in this case character from strs) and become the equivalent of c("1", "2", "3", "4").

    I’m going to assume that you have a list strs with 2 elements and that what you actually want is a data.frame (which is able to hold different types).

    In either case, let’s convert strs into a character first:

    strs2 <- unlist(strs)
    [1] "row1" "row2"
    

    Note that this is the same as if you’d created it via c("row1", "row2").
    Next, we’ll create a data.frame:

    result <- data.frame(strs2, nums)
      strs2 X1 X2
    1 row1   1  3
    2 row2   2  4
    

    This is essentially the same solution that @thelatemail provided.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm making a simple page using Google Maps API 3. My first. One marker
I am reading a book about Javascript and jQuery and using one of the
We're building an app, our first using Rails 3, and we're having to build
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.