# Help to plot interval data with R using histogram?

I have some data from a questionnaire: How many hours per week did you spend on x? 1-3, 4-6, 7-10, 11-14, >14?

I get this data into R as a column of a dataframe.

surv$Q2 #[1] 4 : 11 -14 hours 3 : 7-10 hours 3 : 7-10 hours 4 : 11 -14 hours 3 : 7-10 hours 4 : 11 -14 hours #[7] 3 : 7-10 hours 3 : 7-10 hours 3 : 7-10 hours 1 : 1-3 hours 3 : 7-10 hours 2 : 4-6 hours

How can I get a histogram of this data (and also is there a function to allow me to easily compute the means?)

## Answers

Assuming these are your data, you can display the frequencies using barplot.

x <- c(1, 2, 21, 12, 0) names(x) <- c("1-3", "4-6", "7-10", "11-14", ">14") x # 1-3 4-6 7-10 11-14 >14 # 1 2 21 12 0 barplot(x)

See also the documentation for function hist.