Q:

Proportion of data in a sample in R

I have a variable of vehicles: 

vehicleType <- c("suv", "suv", "minivan", "car", "suv", "suv", "car", "car", "car", "car", "minivan", "car", "truck", "car", "car", "car", "car", "car", "car", "car", "minivan", "car", "suv", "minivan", "car", "minivan", "suv", "suv", "suv", "car", "suv", "car", "car", "suv", "truck", "truck", "minivan", "suv", "car", "truck", "suv", "suv", "car", "car", "car", "car", "suv", "car", "car", "car", "suv", "car", "car", "car", "truck", "car", "car", "suv", "suv", "minivan", "suv", "car", "car", "car", "car", "car", "minivan", "suv", "car", "car", "suv", "minivan", "car", "car", "car", "minivan", "minivan", "minivan", "car", "truck", "car", "car", "car", "suv", "suv", "suv", "car", "suv", "suv", "car", "suv", "car", "minivan", "car", "car", "car", "car", "car", "car", "car")

How can I calculate the proportion of SUV's in the sample in R?
Thanks in advance.

A:

We can use mean
mean(vehicleType=="suv")
#[1] 0.26

Or to find the proportions of all the elements, use prop.table
prop.table(table(vehicleType))
#   vehicleType
#   car minivan     suv   truck 
#  0.55    0.13    0.26    0.06 

