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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:18:51+00:00 2026-06-11T11:18:51+00:00

I’m trying to create a dummy variable for good and bad by extracting numbers

  • 0

I’m trying to create a dummy variable for “good” and “bad” by extracting numbers from the HOUSE column. What I want to do is, the house is “good” if the value in the column HOUSE is 1,2,9 and otherwise “bad”)

I am pasting the dput output of my data.frame object.

## dput output assigned to the housetype variable

structure(list(Price = c(10L, 20L, 31L, 41L, 52L, 63L, 45L, 63L, 
64L, 45L), Location = structure(c(4L, 7L, 6L, 3L, 2L, 4L, 5L, 
1L, 6L, 8L), .Label = c("AK", "ATL", "BOS", "DC", "GA", "MA", 
"NYC", "PA"), class = "factor"), HOUSE = c(1L, 1L, 1L, 2L, 6L, 
7L, 8L, 9L, 10L, 11L)), .Names = c("Price", "Location", "HOUSE"
), class = "data.frame", row.names = c(NA, -10L))

How can I create a dummy variable in a way that each variable still contains the other information? (price and location)

Thanks!!!

  • 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-11T11:18:52+00:00Added an answer on June 11, 2026 at 11:18 am

    You can simply do:

    housetype$quality <- ifelse(housetype$HOUSE %in% c(1,2,9), "good", "bad")
    housetype
    #        Price Location HOUSE quality
    # 1     10       DC     1    good
    # 2     20      NYC     1    good
    # 3     31       MA     1    good
    # 4     41      BOS     2    good
    # 5     52      ATL     6     bad
    # 6     63       DC     7     bad
    # 7     45       GA     8     bad
    # 8     63       AK     9    good
    # 9     64       MA    10     bad
    # 10    45       PA    11     bad
    

    Instead of creating a vector of characters (“good” or “bad”), it is good practice to create a flag variable, i.e. a vector of type logical (TRUE or FALSE). It uses less memory and is in general easier to work with:

    housetype$is.good <- housetype$HOUSE %in% c(1,2,9)
    housetype
    #    Price Location HOUSE quality is.good
    # 1     10       DC     1    good    TRUE
    # 2     20      NYC     1    good    TRUE
    # 3     31       MA     1    good    TRUE
    # 4     41      BOS     2    good    TRUE
    # 5     52      ATL     6     bad   FALSE
    # 6     63       DC     7     bad   FALSE
    # 7     45       GA     8     bad   FALSE
    # 8     63       AK     9    good    TRUE
    # 9     64       MA    10     bad   FALSE
    # 10    45       PA    11     bad   FALSE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

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.