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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:08:40+00:00 2026-06-12T14:08:40+00:00

Consider the following R code. > x = cbind(c(10, 20), c([], []), c([[1,2]],[[1,3]])) >

  • 0

Consider the following R code.

> x = cbind(c(10, 20), c("[]", "[]"), c("[[1,2]]","[[1,3]]"))
> x
     [,1] [,2] [,3]     
[1,] "10" "[]" "[[1,2]]"
[2,] "20" "[]" "[[1,3]]"

Similarly

> x = rbind(c(10, "[]", "[[1,2]]"), c(20, "[]", "[[1,3]]"))
> x
     [,1] [,2] [,3]     
[1,] "10" "[]" "[[1,2]]"
[2,] "20" "[]" "[[1,3]]"

Now, I don’t want the integers 10 and 20 to be converted to strings.
How can I perform this operation without any such conversion? I would of
course also like to know why this conversion happens. I looked at
the cbind help and also tried Googling, but had no luck finding a
solution. I also believe that in some cases. R converts strings to
factors, and I don’t want that to happen either, though it doesn’t seem
to be happening here.

  • 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-12T14:08:41+00:00Added an answer on June 12, 2026 at 2:08 pm

    Vectors and matrices can only be of a single type and cbind and rbind on vectors will give matrices. In these cases, the numeric values will be promoted to character values since that type will hold all the values.

    (Note that in your rbind example, the promotion happens within the c call:

    > c(10, "[]", "[[1,2]]")
    [1] "10"      "[]"      "[[1,2]]"
    

    If you want a rectangular structure where the columns can be different types, you want a data.frame. Any of the following should get you what you want:

    > x = data.frame(v1=c(10, 20), v2=c("[]", "[]"), v3=c("[[1,2]]","[[1,3]]"))
    > x
      v1 v2      v3
    1 10 [] [[1,2]]
    2 20 [] [[1,3]]
    > str(x)
    'data.frame':   2 obs. of  3 variables:
     $ v1: num  10 20
     $ v2: Factor w/ 1 level "[]": 1 1
     $ v3: Factor w/ 2 levels "[[1,2]]","[[1,3]]": 1 2
    

    or (using specifically the data.frame version of cbind)

    > x = cbind.data.frame(c(10, 20), c("[]", "[]"), c("[[1,2]]","[[1,3]]"))
    > x
      c(10, 20) c("[]", "[]") c("[[1,2]]", "[[1,3]]")
    1        10            []                 [[1,2]]
    2        20            []                 [[1,3]]
    > str(x)
    'data.frame':   2 obs. of  3 variables:
     $ c(10, 20)              : num  10 20
     $ c("[]", "[]")          : Factor w/ 1 level "[]": 1 1
     $ c("[[1,2]]", "[[1,3]]"): Factor w/ 2 levels "[[1,2]]","[[1,3]]": 1 2
    

    or (using cbind, but making the first a data.frame so that it combines as data.frames do):

    > x = cbind(data.frame(c(10, 20)), c("[]", "[]"), c("[[1,2]]","[[1,3]]"))
    > x
      c.10..20. c("[]", "[]") c("[[1,2]]", "[[1,3]]")
    1        10            []                 [[1,2]]
    2        20            []                 [[1,3]]
    > str(x)
    'data.frame':   2 obs. of  3 variables:
     $ c.10..20.              : num  10 20
     $ c("[]", "[]")          : Factor w/ 1 level "[]": 1 1
     $ c("[[1,2]]", "[[1,3]]"): Factor w/ 2 levels "[[1,2]]","[[1,3]]": 1 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following code: My problem is: 1) I can't seem to cast the errors
Consider the following code: $('div').click(function(){ $(this).animate({height:100}, 500) $(this).css({opacity:1}); }); Versus: $('div').click(function(){ $(this).animate({height:100}, 500); })
This is rather interesting, I think. Consider following code, both the window.onload and body
Consider the following code: function authenticate(){ $this->session->set_userdata('logged_in', true); } How do I return this
Consider the following code ( http://jsfiddle.net/FW36F/1/ ): <input type=checkbox onchange=alert(this.checked)> <button onclick=document.getElementsByTagName('input')[0].checked=!document.getElementsByTagName('input')[0].checked;>toggle</button> If you
Consider the following code example: TempList.ForEach(Function(obj) obj.Deleted = True End Function) And this one:
Consider the following code: function Robot(weapon) { this.weapon = weapon; this.fire = function() {
Consider the following code. This code almost implements Chicken Scheme style recursion where most
Consider the following code: $(a).attr(disabled, disabled); In IE and FF, this will make anchors
Consider following code, I want to make it a thread safe class, so that

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.