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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:08:01+00:00 2026-06-16T20:08:01+00:00

There is an interesting option drop = TRUE in data.frame filtering, see excerpt from

  • 0

There is an interesting option drop = TRUE in data.frame filtering, see excerpt from help('[.data.frame'):

Usage

S3 method for class ‘data.frame’

x[i, j, drop = ]

But when I try it on data.frame, it doesn’t work!

> df = data.frame(a = c("europe", "asia", "oceania"), b = c(1, 2, 3))
>
> df[1:2,, drop = TRUE]$a
[1] europe asia  
Levels: asia europe oceania     <--- oceania shouldn't be here!!
>

I know there are other ways like

df2 <- droplevels(df[1:2,])

but the documentation promised much more elegant way to do this, so why it doesn’t work? Is it a bug? Because I don’t understand how this could be a feature…

EDIT: I was confused by drop = TRUE dropping factor levels for vectors, as you can see here. It is not very intuitive that [i, drop = TRUE] drops factor levels and [i, j, drop = TRUE] does not!!

  • 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-16T20:08:02+00:00Added an answer on June 16, 2026 at 8:08 pm

    The documentation clearly states:

    drop : logical. If TRUE the result is coerced to the lowest possible
    dimension. The default is to drop if only one column is left, but not
    to drop if only one row is left.

    This means that if drop = TRUE and the filtered data.frame results in a single column or row, the result is coerced to a vector/list instead of returning a single-column/single-row data.frame.

    Therefore, this argument has no relation with levels dropping, and so the right way to eliminate exceeding levels is the one you mentioned (i.e. using droplevels function).

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

Sidebar

Related Questions

Is there a better way than using globals to get interesting values from a
On this page , I see something interesting: Note that there is a fast-path
there's this interesting problem i can not solve myself. I will be very glad,
There was an interesting problem in C++, but it was more about architecture. There
There is this interesting game, that has numbers in a grid, where each number
I'm working with an off-the-shelf application at my company and there is an interesting
I realize there is a very interesting technique, to get Context in Android in
Some days ago I looked at boost sources and found interesting typedef . There
Is there any technique available in Java for intercepting messages (method calls) like the
We have an interesting problem that I was hoping someone could help to shed

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.