aggregate - How to calculate the number of pixels used when aggregating in R? -
i have 2 binary files (1440*720) same dimensions: want take average of first file based on second file values (intervals),the values of file range 1 7. whenever values in second file range between 0-1, calculate corresponding average in first file , return result,do same thing 2-3,3-4,5-6,7-8.no data values assigned na.
1- read first file :
conne <- file("c:\\corr.bin","rb") corr <- readbin(conne, numeric(), size=4, n=1440*720, signed=true) #please assume matrix of 720*1440 dimnsions
2- read second file :
conne1 <- file("c:\\use.bin","rb") cus <- readbin(conne1, numeric(), size=4, n=1440*720, signed=true) #please assume matrix of 720*1440 dimnsions
calculate:
cusbreak <- cut(cus,1:8)) aggregate(corr, list(cusbreak), mean, na.rm=true)
this worked fine need know number of pixels used , percentage out of total number of pixels.
results group.1 x number of pixels percentage (out of total number of pixcels) 1 (0,1] 0.5 ? ? 2 (1,2] 0.23 ? ? 3 (2,3] 0.65 ? ? 4 (3,4] 0.3 ? ? 5 (4,5] 0.36
make function use in aggregate return more 1 value. example:
aggregate(corr, list(cusbreak), function(values){ c( "x" = mean(values), "pixels" = length(values), "percent" = length(values) / length(corr) * 100 ) }, na.rm=true)
Comments
Post a Comment