0

I have data that looks like this:

'data.frame':   798 obs. of  16 variables:
 $ READMIT.ENCOUNTER   : int  (intentionally blank)
 $ MRN                 : int  (intentionally blank)
 $ READMIT.SOURCE      : Factor w/ 5 levels "Emergency Unit",..: 5 1 1 1 5 1 1 1 1 1 ...
 $ READMIT.DATE        : Factor w/ 300 levels "1/1/2013","1/11/2013",..: 83 25 92 88 4 92 26 18 24 9 ...
 $ READMIT.DISC.DATE   : Factor w/ 284 levels "1/10/2013","1/11/2013",..: 10 8 22 22 14 26 3 25 1 112 ...
 $ READMIT.MONTH       : int  1 1 1 1 1 1 1 1 1 2 ...
 $ READMIT.YEAR        : int  2013 2013 2013 2013 2013 2013 2013 2013 2013 2013 ...
 $ LOS                 : int  11 10 4 7 11 8 4 4 3 18 ...
 $ INTERIM             : int  24 27 27 19 29 4 21 9 18 18 ...
 $ READMIT.INSURANCE   : Factor w/ 33 levels "A12","A13","B03",..: 1 2 1 23 9 4 19 2 2 2 ...
 $ READMIT.MDC         : Factor w/ 18 levels "CIRCULATORY DZ",..: 17 17 7 13 1 14 17 1 17 17 ...
 $ READMIT.DRG         : Factor w/ 141 levels "100","102","103",..: 19 19 65 127 41 80 18 42 20 21 ...
 $ READMIT.DX.CLASF    : Factor w/ 195 levels "ABDOMINAL ANEURYSM WITHOUT MENTION OF RUPTURE",..: 126 125 189 117 16 116 51 15 126 161 ...
 $ READMIT.ADMITTING.DR: Factor w/ 59 levels (intentionally blank)
 $ READMIT.ATTENDING.DR: Factor w/ 59 levels (intentionally blank)
 $ READMIT.HOSP.SVC    : Factor w/ 8 levels "CCU","MED","MIC",..: 2 2 2 5 2 2 2 2 2 2 ...

From that data there are only two (2) READMIT.SOURCE ID'S that I am interested in, those being "Emergency Unit" and "Transfer from Long Term Care", the reason being is that out of 798 observations these two account for 791 of them.

At first I tried subset() which was a no beuno. So now I have done the following:

er <- data.frame(radata[radata$READMIT.SOURCE == "Emergency Unit",])
lt <- data.frame(radata[radata$READMIT.SOURCE == "Transfer from Long Term Care",])

The above two lines gave me exactly what I need. My question is now, how do I make a new data.frame that will encompass both of the newly created? The structure of er and lt are exactly the same as what is shown above.

Thank you,

2
  • 1
    radata[radata$READMIT.SOURCE %in% c("Emergency Unit", "Transfer from Long Term Care"),] Commented Jan 6, 2014 at 19:40
  • @Roland thank you, please post as answer and I'll accept when I can Commented Jan 6, 2014 at 19:46

1 Answer 1

3

Please read some more tutorials and introductions to R and pay special attention to subsetting. You are looking for %in%:

radata[radata$READMIT.SOURCE %in% c("Emergency Unit", "Transfer from Long Term Care"),]

Of course, you could also take your two data.frames and use rbind on them.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.