-4

I have a data frame in R with around 4 millions observations. There are 9 different values/levels in column "Property Type" and I want to simplify it by changing those 9 values to be either "House" or "Apartment". How can I do this?

  • Example data:

Property_Type

privateHome

oneBedApt

Apt

twoBedApt

  • Expected output:

Property_Type

House

Apartment

Apartment

Apartment

A. sham
  • 13
  • 3
  • 5
    Welcome to Stack Overflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – zx8754 Apr 19 '17 at 21:07
  • Thanks @zx8754 for your comment. I actully thought my question is clear. Is there something specific I need to explain/change? – A. sham Apr 19 '17 at 21:22
  • 1
    Question is clear and probably pretty basic problem. We don't know for sure until example data and expected output is provided. – zx8754 Apr 19 '17 at 21:28
  • @zx8754 Got it, much appreciated! – A. sham Apr 19 '17 at 21:47
  • You mentioned there are 9 levels. What are the other ones? – www Apr 19 '17 at 22:24

1 Answers1

0

I don't know how does exactly your data look like so I made my fake data:

         Flat col1 col2 col3
1 privateHome  qwe  rty  uio
2   oneBedApt  uio  pas  dfg
3         Apt  dfg  hjk  lzx
4   twoBedApt  lzx  cvb  nmq

d$Flat <- ifelse(grepl("Apt",d$Flat),"Apartment","House")

       Flat col1 col2 col3
1     House  qwe  rty  uio
2 Apartment  uio  pas  dfg
3 Apartment  dfg  hjk  lzx
4 Apartment  lzx  cvb  nmq

Should do the trick

Adamm
  • 2,150
  • 22
  • 30