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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:15:56+00:00 2026-05-26T00:15:56+00:00

Suppose we want to access data from a data frame by row. The examples

  • 0

Suppose we want to access data from a data frame by row. The examples are simplified but when ordering a data frame by row names, for example, (df[order(row.names(df)]) we use the same technique.

If the data frame has one column, we get back an atomic vector:

> df
    x1
a   x
b   y
c   z

> df[1, ] # returns atomic vector
[1] x 

If the data frame has two columns, we get back a 1-row data frame including the row name:

> df
    x1 x2
a   x  u
b   y  v
c   z  w 

> df[1, ] # returns data frame
   X1 X2
a  x  u 

I don’t understand why the same operation on the data frame yields two types of results depending on how many columns the frame has.

  • 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-26T00:15:56+00:00Added an answer on May 26, 2026 at 12:15 am

    It’s because the default argument to [ is drop=TRUE.

    From ?"["

    drop
    For matrices and arrays. If TRUE the result is coerced to the
    lowest possible dimension (see the examples). This only works for
    extracting elements, not for the replacement. See drop for further
    details.

    > dat1 <- data.frame(x=letters[1:3])
    > dat2 <- data.frame(x=letters[1:3], y=LETTERS[1:3])
    

    The default behaviour:

    > dat[1, ]
         row sessionId scenarionName stepName duration
    [1,]   1      1001             A    start        0
    
    > dat[2, ]
         row sessionId scenarionName stepName duration
    [1,]   2      1001             A    step1      2.2
    

    Using drop=FALSE:

    > dat1[1, , drop=FALSE]
      x
    1 a
    
    > dat2[1, , drop=FALSE]
      x y
    1 a A
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I'm accessing a DataTable from multiple threads. If I want to access a
Suppose I want to fetch data into an anonymous object (i.e. fetch data from
Suppose you want to make an async request in JavaScript, but you want to
Suppose I want to execute code, for example value += 5 inside a namespace
How can i pass the different types of errors from Data access layer to
I am creating a data access layer where I want to handle exceptions that
Suppose I want to run some program which requests too many permissions. For example,
Suppose I'm entertaining a business model that offers free access to my propritary data
Suppose I want to open a file in an existing Emacs session using su
Suppose I want to implement a reasonably efficient 'keyword recognition algorithm', that is first

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.