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.


Need Your Help

Code folding isn't working in Management Studio?

sql ssms

I have SQL Management Studio 10.50.1600.1, and I have Outline statements turned on in Tools -&gt; Options -&gt; Text Editor -&gt; Transact-SQL -&gt; IntelliSense, but alas it's not giving me the ex...

CGContextSetShadowWithColor: shadow is flipped in UIView

uiview cgcontext shadow flip

I am developing an iPhone application in which I want set the shadow for the path that I am drawing on UIView's context.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.