[R] Coarsening the Resolution of a Dataset

jim holtman jholtman at gmail.com
Sun Jul 27 01:23:47 CEST 2008


Here is one approach for using the average of each interval:

> # generate some test data; assume 1.0 is one degree
> min.5 <- 5 / 60   # portion of degree for 5 minutes
> n <- 100   # number of data points
> myData <- cbind(interval=seq(0, by=min.5, length=n), value=runif(n))
> # create breaks every 0.5 degrees and make sure the range covers everything
> breaks <- c(seq(min(myData[,'interval']), max(myData[, 'interval']), by=0.5), Inf)
> # create the 'cuts' in the data
> myCuts <- cut(myData[, 'interval'], breaks, include.lowest=TRUE)
> # samples in each period
> table(myCuts)
myCuts
[0,0.5] (0.5,1] (1,1.5] (1.5,2] (2,2.5] (2.5,3] (3,3.5] (3.5,4]
(4,4.5] (4.5,5] (5,5.5] (5.5,6] (6,6.5] (6.5,7] (7,7.5]
      7       6       6       6       6       6       6       6
6       6       6       6       6       6       6
(7.5,8] (8,Inf]
      6       3
> # compute the average of each sample
> aggregate(myData[, 'value'], list(myCuts), FUN=mean)
   Group.1         x
1  [0,0.5] 0.6159838
2  (0.5,1] 0.3393176
3  (1,1.5] 0.7425675
4  (1.5,2] 0.7360632
5  (2,2.5] 0.5296324
6  (2.5,3] 0.4908095
7  (3,3.5] 0.4415784
8  (3.5,4] 0.4930957
9  (4,4.5] 0.4455074
10 (4.5,5] 0.5126061
11 (5,5.5] 0.7512261
12 (5.5,6] 0.5406761
13 (6,6.5] 0.4331468
14 (6.5,7] 0.4721029
15 (7,7.5] 0.5113987
16 (7.5,8] 0.4565146
17 (8,Inf] 0.1510198
>
>


On Sat, Jul 26, 2008 at 7:07 PM, Steve Murray <smurray444 at hotmail.com> wrote:
>
> Dear all,
>
> I have gridded data at 5' (minutes) resolution, which I intend to coarsen to 0.5 degrees. How would I go about doing this in R? I've had a search online and haven't found anything obvious, so any help would be gratefully received.
>
> I'm assuming that there will be several 'coarsening' techniques available - I'm after something fairly simple, which for example, just takes an average of each 0.5 degree portion of the current dataset.
>
> If someone is able to point me in the right direction, then I'd be very grateful.
>
> Many thanks,
>
> Steve
>
> _________________________________________________________________
> Play and win great prizes with Live Search and Kung Fu Panda
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list