[R] (no subject)

PIKAL Petr petr.pikal at precheza.cz
Fri Oct 18 10:25:33 CEST 2013


Hi

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Manuel Figueroa
> Sent: Friday, October 18, 2013 6:24 AM
> To: r-help at r-project.org
> Subject: [R] (no subject)
> 
> I have a simple table, 2 columns and 1994 rows. First row, "Crime" is
> how many crimes happen every month per 100000 inhabitants and second
> row is "Income" which contains the average income recorded in a city.
> 
> here's the head(dataset):
> 
>     Crime      Income
> 1 356.5152 4285.720
> 2 734.5625 4114.291
> 3 541.5171 3542.861
> 4 292.1667 4057.148
> 5 219.7747 4457.149
> 6 308.2538 6114.296
> 
> I want to stratify the crime based on income and then box plot each
> stratum to compare. Also I need to get the variance of each stratum in
> a table.

Homwork? There is no homework policy ot the list. Anyway, below are few hints.

> 
> this is the summary of the Income column:
> 
> Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
> 2000    3257    3714    4001    4457    7714
> 
> 
> Closer I've been able to get is this:
> strata=table(cut(dataset$Income, breaks, right= FALSE))
> 
> where breaks is
> > breaks
>  [1] 2000 3500 5000 6500 8000
> 
> this gives me as result:
> > cbind(strata)
>                           strata
> [2e+03,3.5e+03)      805
> [3.5e+03,5e+03)      894
> [5e+03,6.5e+03)      206
> [6.5e+03,8e+03)       89
> 
> 
> I'm not even sure if that's the right way to get the strata.

It probably is unless you want breaks at other incomes. 

> 
> *The important thing here is I need to find a way to get a boxplot of
> the Crime values in each stratum and the variance too.
> *

Split crime by strata and make boxplot. See

?cut
?split
?boxplot

or use ggplot2.

For var table see

?aggregate
?sd
?var

Regards
Petr

> Thanks so much in advance.
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list