'How to separate variable "race" to make histograms for another variable
I have the following DataFrame:
head(SB_xlsx)
## patnum hospstay lowph pltct race bwt gest inout twn lol magsulf
## 1 1 34 NA 100 white 1250 35 born at duke 0 NA NA
## 2 2 9 7.250000 244 white 1370 32 born at duke 0 NA NA
## 3 3 -2 7.059998 114 black 620 23 born at duke 0 NA NA
## 4 4 40 7.250000 182 black 1480 32 born at duke 0 NA NA
## 5 5 2 6.969997 54 black 925 28 born at duke 0 NA NA
## 6 6 62 7.189999 NA white 940 28 born at duke 0 NA NA
## meth toc delivery apg1 vent pneumo pda cld sex dead
## 1 0 0 abdominal 8 0 0 0 0 female 0
## 2 1 0 abdominal 7 0 0 0 0 female 0
## 3 0 1 vaginal 1 1 0 0 NA female 1
## 4 1 0 vaginal 8 0 0 0 0 male 0
## 5 0 0 abdominal 5 1 1 0 0 female 1
## 6 1 0 abdominal 8 1 0 0 0 female 0
I need to create 4 histograms comparing birth weight (bwt) to each of the 4 races ("white", "black", "native american", and "oriental") under the "race" variable. How would I need to go about separating out the races so I could make the histograms for bwt?
I had to make a histogram for all of the bwts regardless of race, which the code is shown below. I know how to formulate histograms, but I'm not sure how to separate out races so I can make the 4 race specific ones.
hist(SB_xlsx$bwt, ylab="frequency", xlab="Birth Weight", main="Histogram of Birth Weight")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
