I have data on people who died in a train crash and their ages.
For Example:
file <- data.frame(
Survived = sample(0:1, 100, replace=TRUE),
Age = sample(0:100, 100, replace=TRUE))
I would like to create a histogram in R where each bin measures the people who died as a percentage of the total amount of people in the data set contained in the bin range.
Here is what I have so far:
hist(file[which(file$Survived==1),]$Age, freq=FALSE)
But this only returns a histogram with the values as a percentage of the whole data set. Like so:Histogram of Sample Data
I need a percentage of the particular age group so that if all the people aged 0-10 died the histogram bar would be at 100% in that age group.