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

  • Home
  • SEARCH
  • 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 9162259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:10:04+00:00 2026-06-17T14:10:04+00:00

I have the following to create a data frame. My problem is that the

  • 0

I have the following to create a data frame. My problem is that the data frame row names display as [1,],[2,],[3,],[4,], etc instead of just 1,2,3,4,etc (see below for outputs). Why and how can I fix this to just have my row names show as usual (incremented number).

Code:

df <- data.frame(id=c("id"),nobs=c("nobs"))
df <- cbind(id,nobs)
df

id and nobs are two vectors with 5 numeric values each…

Current output:
     id nobs
[1,]  2 3653
[2,]  4 3653
[3,]  8 1462
[4,] 10 1097
[5,] 12  732

Desired output:
   id nobs
1  2 3653
2  4 3653
3  8 1462
4 10 1097
5 12  732
  • 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-17T14:10:05+00:00Added an answer on June 17, 2026 at 2:10 pm

    Note: I don’t suggest that you should use either of these methods. If you want a data.frame, you can create it directly as Paul has showed (or you yourself have done). This is just to illustrate why this happens. Although sometimes when using sapply for example, the output would be a matrix and you might want to bind 2 such matrices and have them as a data.frame.

    From the help page for cbind (?cbind):

    The functions cbind and rbind are S3 generic, with methods for data frames. The data frame method will be used if at least one argument is a data frame and the rest are vectors or matrices.

    Data frame methods

    The cbind data frame method is just a wrapper for data.frame(…, check.names = FALSE). This means that it will split matrix columns in data frame arguments, and convert character columns to factors unless stringsAsFactors = FALSE is specified.

    So, if you pass two vectors, the wrapper for data.frame won’t be called. Hence, you obtain a matrix.

    What can you do?
    1) you could create and pass at least one data.frame argument to cbind
    2) wrap the cbind argument with a as.data.frame(.).

    x <- 1:5
    y <- 6:10
    > cbind(data.frame(x), y)
      x  y
    1 1  6
    2 2  7
    3 3  8
    4 4  9
    5 5 10
    
    > as.data.frame(cbind(x,y))
      x  y
    1 1  6
    2 2  7
    3 3  8
    4 4  9
    5 5 10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a requirement to create a data structure that has the following
I have a data frame that has a format like the following: Month Frequency
I have the following table: CREATE TABLE [dbo].[Data] ( [Id] UNIQUEIDENTIFIER NOT NULL, [Data]
Suppose that we have following tables create table Employee( 2 EMPNO NUMBER(3), 3 ENAME
Let's say you have a data frame generated by the following commands: date <-
I have a semi-melted data frame that looks like this: head(final_melt) Group Source variable
Let's say I have the following data frame. dat <- data.frame(city=c(Chelsea,Brent,Bremen,Olathe,Lenexa,Shawnee), tag=c(rep(AlabamaCity,3), rep(KansasCity,3))) I
I have a set of data such as the following: annual_exp<-as.data.frame(c(6000,4200,240001,750,20000,3470,10500,2400,2280,36000,3600,20000,2000,12000,1200,3000,4500,64000)) annual_exp<-as.data.frame(annual_exp) I want
I have the following data and am trying to create a barplot in R
Let say I have the following data frame in R: df1 <- data.frame(Item_Name =

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.