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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:20:27+00:00 2026-05-23T16:20:27+00:00

Let me elaborate with an example: mystr = foo intvector = c(1,2,3,4,5) trial1 =

  • 0

Let me elaborate with an example:

mystr = "foo"
intvector = c(1,2,3,4,5)
trial1 = c(mystr,intvector)
sapply(trial1,class)

trial2 = mat.or.vec(1+length(intvector),1)
trial2[1] = mystr
trial2[2:length(trial2)] = intvector
sapply(trial2,class)

Both return

        foo           1           2           3           4           5 
"character" "character" "character" "character" "character" "character" 

As you can see, R converts/casts the numeric type to character type for me, which is not what I want. Thanks 🙂

EDIT: I will use the result to append (rbind) it directly to a data.frame, which initially will be empty, so the column classes will not yet be defined.

  • 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-23T16:20:27+00:00Added an answer on May 23, 2026 at 4:20 pm

    I believe this should work. If anyone finds a better solution, without using lists, please let me know.

    trial3 = data.frame(I(mystr), t(intvector))
    sapply(trial3,class)
    

    Produces:

        mystr        X1        X2        X3        X4        X5 
       "AsIs" "numeric" "numeric" "numeric" "numeric" "numeric" 
    

    Note that we have to wrap mystr in I and transpose the intvector in order for this to work.

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

Sidebar

Related Questions

Is it possible to get the enumeration values from a Class? Let me elaborate
let me elaborate more on the Title. Consider for example PHP_FUNCTION(session_start). Will I be
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a
I'm trying to link posts in wordpress. Let me elaborate. In wordpress, you can
Is it possible to send nothing to an object? Let me elaborate. For instance
Let's say I have a class like so: class Gerbil{ int id; float x,y,z;
Let me elaborate on the question... I have a custom CMS (built on codeigniter
Sorry if my question is uncleared. Let me elaborate. I have a rectangle of
I hope that made sense, let me elaborate: There is a table of tracking

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.