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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:08:58+00:00 2026-06-10T02:08:58+00:00

I am attempting to filter data frames that have only one column. This results

  • 0

I am attempting to filter data frames that have only one column. This results in a vector being returned like so:

single.c <- data.frame(col1=c(1,2,3,4,5), row.names=C("r1","r2","r3","r4","r5"))
single.c[single.c$col1 > 2,]

[1] 3 4 5

What I actually want is the data returned like it is for multi-column dataframes:

multi.c <- data.frame(col1=c(1,2,3,4,5), col2=c(1,2,3,4,5), row.names=c("r1","r2","r3","r4","r5"))
multi.c[multi.c$col2 > 2,]

   col1 col2
r3    3    3
r4    4    4
r5    5    5

I can see it makes sense to return a vector if there are no other columns, but generally I want see what rows have given that result too. Why does this happen, and is there an easy way to keep the data frame shape in the result, including the rownames?

  • 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-10T02:08:59+00:00Added an answer on June 10, 2026 at 2:08 am

    Use the drop argument to the select functions:

    single.c[single.c$col1 > 2, , drop = FALSE]
    
    #   col1
    #r3    3
    #r4    4
    #r5    5
    

    From documentation for [:

    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.

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

Sidebar

Related Questions

I have an action that looks like this: [Post] [PopulateModelFromId] public ActionResult ChangeName( string
I have one very large text file(27GB) that I am attempting to make smaller
I am attempting to filter a column in an Obout Grid that has been
I am having trouble with a MOSS FulltextSqlQuery when attempting to filter People results
Attempting to use the data series from this example no longer passes the JSONLint
I am attempting to Filter a large list of tabular data with text keyup.
So I am attempting to create a search field that will filter contacts on
I am attempting to export data to a excel spreadsheet and so open that
I'm attempting to refactor a cumbersome LINQ-to-SQL data layer with an entity framework one.
I am attempting to map the filter functor with one of the member methods

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.