I want to subtract my first daily date of a month with its second date than the second date data with the third date and so on using DIff in R.213-Lon,78-Lat,30-days data. I am getting zero as output.
My code begains:
cdf<-nc_open(file.choose()) //open my netcdf file
rain1 <- ncvar_get( cdf, "RAINNC" ) //extrct varaible
dim(rain1)
[1] 213 78 30
obs1<-array(0,c(213,78,30))// dummay array for output
no<-array(0,c(213,78,30))
for( i in 1 :dim(rain1)[1]){
for( j in 1 :dim(rain1)[2]){
for( k in 1 :dim(rain1)[3]){
if(!is.na(rain1)[3]){
obs[i,j] <- diff(k ,lag = 1)}
else { no[i,j] <- NA }
}}}