Im trying to take a column of my data under the variable (age) and see what percent of that age is above 65 years old. how would i go about this??
If you have a data frame named DF and a column named age:
mean(DF$age > 65)
The comparison DF$age > 65 returns TRUE or FALSE. TRUE equals 1 and FALSE equals 0. The mean of the comparison is thus the fraction that are TRUE.
this just gives me the mean of people above 65 years old. Im hoping for the percent of people above 65 years old
Three of the ten data points in the following data frame are above 65. The calculation returns 0.3, not the average of the ages.
DF <- data.frame(age = c(13, 67, 23, 45, 78, 35, 21, 80, 64, 2)) mean(DF$age > 65) #>  0.3
Created on 2020-02-05 by the reprex package (v0.3.0)
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.