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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:35:11+00:00 2026-06-14T20:35:11+00:00

Possible Duplicate: dropping factor levels in a subsetted data frame in R I am

  • 0

Possible Duplicate:
dropping factor levels in a subsetted data frame in R

I am getting a little frustrated with R here, it would be great if anyone could help me with the following:I am trying to pull a subset out of my dataset but it does not work properly.

Specifics:
I have a spreadsheet with words and different features associated with each word
e.g. word article length …
…
Now I am trying to look at individual words, e.g. pull out all instances where the word is “hairbrush”. To do so, I tried:

hairbrush=subset(dataset, word=="hairbrush")

This seems to work fine and gives me the right dataset when I look at it with fix or head. However, as soon as I try to do things like xtabs or any kind of computation, I do not get very far because all the other words are still “there” and mess up my stats. E.g. when I do levels, it gives me “hairbrush”, but also all other 200 words. All the data pertaining to these “hidden words” is NA but it still messes up my stats.

Is that the usual behavior of subset? Or am I doing something wrong? Or is this the wrong approach?

Oh, and in some similar questions on Google, people always asked for the output of str, so here it is:

> str(hairbrush)
'data.frame':   41 obs. of  10 variables:
 $ id       : Factor w/ 1352 levels "1-1-1-11-a.eaf",..: 210 240 267 295 320 351 378 403 427 452 ...
 $ speaker  : num  24 25 26 28 29 30 32 33 34 35 ...
 $ loc      : Factor w/ 2 levels "nb","xx": 1 1 1 1 1 1 1 1 1 1 ...
 $ gilbertno: Factor w/ 27 levels "1","10","108",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ tword    : Factor w/ 65 levels "abaddream","afuneral",..: 4 4 4 4 4 4 4 4 4 4 ...
 $ word     : Factor w/ 228 levels "abbe","aepfel",..: 164 93 99 93 92 100 94 94 28 93 ...
 $ loan     : Factor w/ 5 levels "FILE","maybe",..: 4 3 5 3 5 5 3 3 3 3 ...
 $ article  : Factor w/ 40 levels "a","das","dat",..: 34 34 33 33 34 34 34 34 13 34 ...
 $ gender   : Factor w/ 13 levels "a","af","amn",..: 11 11 7 7 11 11 11 11 7 11 ...
 $ comment  : Factor w/ 4 levels "0","die macht ja vorschlaege",..: 1 1 1 1 1 1 1 1 1 1 ...
  • 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-14T20:35:13+00:00Added an answer on June 14, 2026 at 8:35 pm

    You need to use droplevels after subsetting to clean out unused levels.

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

Sidebar

Related Questions

Possible Duplicate: dropping factor levels in a subsetted data frame in R I have
Possible Duplicate: dropping factor levels in a subsetted data frame in R I'm trying
Possible Duplicate: dropping factor levels in a subsetted data frame in R I have
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: C# driver development? I would like to know if I can do
Possible Duplicate: Matlab gives wrong answer Can anyone explain to me why the following
Possible Duplicate: how to add a reference to the system.data.SQLite.dll to the windows phone
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want

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.