[R] How to calculate the statistcs for extracted region?

David Winsemius dwinsemius at comcast.net
Wed Jun 13 19:32:28 CEST 2012


On Jun 13, 2012, at 12:55 PM, Jonsson wrote:

> I have a binary file(a) with size of (360 720 )for the globe.I wrote  
> the code
> given below to read and extract an area (south america)from that  
> file. when
> I use summary for the whole file I got:
> summary(a, na.rm=FALSE)
> Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's
> 0.00    1.00    3.00    4.15    7.00   20.00  200083 .
>
> But when I used summary for the region(b) which I extracted, I got  
> many
> V1,V2, V3. Which is not right I should have got one line (as for  
> a )not many
> V1,V2.

Actually the expected behavior with summary() on a matrix object is a  
column by column summary.

 > summary(matrix(1:16,4))
        V1             V2             V3              V4
  Min.   :1.00   Min.   :5.00   Min.   : 9.00   Min.   :13.00
  1st Qu.:1.75   1st Qu.:5.75   1st Qu.: 9.75   1st Qu.:13.75
  Median :2.50   Median :6.50   Median :10.50   Median :14.50
  Mean   :2.50   Mean   :6.50   Mean   :10.50   Mean   :14.50
  3rd Qu.:3.25   3rd Qu.:7.25   3rd Qu.:11.25   3rd Qu.:15.25
  Max.   :4.00   Max.   :8.00   Max.   :12.00   Max.   :16.00

>
> Here is the code:
> X <- c(200:300)
> Y <- c(150:190)
> conne <- file("C:\\initial-WTD.bin", "rb")
> a=readBin(conne, numeric(), size=4,  n=360*720, signed=TRUE)
> a[a == -9999] <- NA
> y <- matrix(data=a,ncol=360,nrow=720)
> image(t(t(y[X,Y])),ylim=c(1,0))
> b = y[X,Y]
> summary(b,na.rm=TRUE)
>
>   V1            V2            V3            V4             
> V5           V6
> V7
>       Min.   : 1.000   Min.   : 1.000   Min.   : 1.000   Min.   :  
> 1.000
> Min.   : 0.000   Min.   : 0.000
> 1st Qu.: 4.000   1st Qu.: 4.000   1st Qu.: 4.000   1st Qu.: 3.000    
> 1st
> Qu.: 2.000   1st Qu.: 2.000
> Median : 5.000   Median : 6.000   Median : 5.000   Median : 5.000    
> Median
> : 5.000   Median : 5.000
> Mean   : 5.808   Mean   : 5.962   Mean   : 5.506   Mean   : 4.946    
> Mean
> : 5.068   Mean   : 4.829
> 3rd Qu.: 6.750   3rd Qu.: 7.000   3rd Qu.: 7.000   3rd Qu.: 6.000    
> 3rd
> Qu.: 7.000   3rd Qu.: 6.000
> Max.   :18.000   Max.   :19.000   Max.   :17.000   Max.   :13.000    
> Max.
> :19.000   Max.   :18.000
>

This is cross-posted from SO. It is no more reproducible here than it  
was there.

Cross-posting is deprecated on Rhelp. Please read the Posting Guide.


>
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-calculate-the-statistcs-for-extracted-region-tp4633295.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list