# [R] Count of Histogram Bins using Shingles with lattice

David L Carlson dcarlson at tamu.edu
Mon Feb 11 17:24:09 CET 2013

```To get the counts in a variable:

> library(lattice)
> set.seed(42)
> vals <- runif(100)*100
> ints <- co.intervals(vals, number=5, overlap=.25)
> shgl <- shingle(vals, ints)
> summary(shgl)

Intervals:
min      max count
1  0.02362834 25.54314    25
2 20.76563596 47.49997    25
3 39.84827982 66.74291    25
4 61.91566269 83.29187    25
5 77.58207495 98.88943    25

[1] 6 7 6 6
> lvls <- attributes(shgl)\$levels
> cts <- colSums(sapply(t(lvls), function(x) ifelse(vals>=x[1]
+      & vals<=x[2],1,0)))
> cts
[1] 25 25 25 25 25

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352

> -----Original Message-----
> From: David L Carlson [mailto:dcarlson at tamu.edu]
> Sent: Monday, February 11, 2013 10:05 AM
> To: 'Burns, Jonathan (NONUS)'; 'r-help at r-project.org'
> Subject: RE: [R] Count of Histogram Bins using Shingles with lattice
>
> You can use the functions in lattice to compute the shingle and display
> the results, but they do not seem to be stored:
>
> > set.seed(42)
> > vals <- runif(100)*100
> > ints <- co.intervals(vals, number=5, overlap=.25)
> > cts <- shingle(vals, ints)
>
> cts contains has the original data and the range of each level. You can
> get the counts in each level with
>
> > summary(cts)
> Intervals:
>           min      max count
> 1  0.02362834 25.54314    25
> 2 20.76563596 47.49997    25
> 3 39.84827982 66.74291    25
> 4 61.91566269 83.29187    25
> 5 77.58207495 98.88943    25
>
> [1] 6 7 6 6
>
> ----------------------------------------------
> David L Carlson
> Associate Professor of Anthropology
> Texas A&M University
> College Station, TX 77843-4352
>
> > -----Original Message-----
> > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> > project.org] On Behalf Of Burns, Jonathan (NONUS)
> > Sent: Friday, February 08, 2013 12:45 PM
> > To: r-help at r-project.org
> > Subject: [R] Count of Histogram Bins using Shingles with lattice
> >
> > I know that I can get a count of histogram bins in base R with
> > plot=FALSE. However, I'd like to do the same thing with lattice.  The
> > problem is that I've set up shingles, and I'd like to get the count
> > within each bin within each shingle.  plot=FALSE doesn't seem to do
> it.
> >
> >
> >
> > 	[[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help