This code bellow will calculate average daily wind speed(measurements are taken every three hours).
library(Matrix) setwd("C:\\Users\\aalyaari\\Desktop\\img") listfile<-dir() long <- file("C:\\Users\\aalyaari\\Desktop\\New folder (5)\\inra.bin", "rb") A=readBin(long, integer(), size=2,n=67420*1, signed=F) ta<-t(A) lot <- file("C:\\Users\\aalyaari\\Desktop\\New folder (5)\\lat.img", "rb") B=readBin(lot, integer(), size=2,n=67420*1, signed=F) tb<-t(B) for (n in 1:length(listfile)) { #h[n]=listfile[n] h=listfile[n] #b[n]=file.info(h[n])$size/67420/4 b=file.info(h[n])$size/67420/4 wind <- file(h, "rb") C=readBin(wind, double(), size=4,n=67420*b, signed=TRUE) D<-matrix(C,nrow=b,ncol=67420) for(d in 1:b) { M <- Matrix(-9999, 360, 720) tm<-t(M) for(i in 1:67420) { tm[ta[i],tb[i]]= round(10 * mean(D[(d-1)*8 + 1:8), i]) } to.write <- sprintf("C:\\Users\\aalyaari\\Desktop\\New folder (6)\\Yar_%00d.bin", d) writeBin(as.integer(tm@x), size=2,to.write) } } the values are measured in kelvin so i want to convert them to degree,therefor I want to subtract all values by 273.15 before talking the average or max.... but did not work.In other words, i want this: every value is subtracted by 273.15 first ,then do other calculations(Min, Max)Can anyone tell me what is wrong.Thanks tm[ta[i],tb[i]]= round(10 * mean(D[((d-1)*8 + 1:8)-273.15), i])) -- View this message in context: http://r.789695.n4.nabble.com/Min-Max-tp4593065p4594774.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@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.