I have the following array which I called station:
A1 <- matrix(runif(120),24,5)
A1[1:12,1]<-2012
A1[13:24,1]<-2013
A1[1:12,2]<-(1:12)
A1[13:24,2]<-(1:12)
A1[1:12,3]<-seq(1,24,by=2)
A1[13:24,3]<-seq(1,24,by=2)
A2 <- matrix(runif(120),24,5)
A2[1:12,1]<-2012
A2[13:24,1]<-2013
A2[1:12,2]<-(1:12)
A2[13:24,2]<-(1:12)
A2[1:12,3]<-seq(1,24,by=2)
A2[13:24,3]<-seq(1,24,by=2)
station <- array(NA,c(24,5,2))
station[,,1] <- A1
station[,,2] <- A2
dimnames(station)[[2]]<-c('year','month','day','win_3','win_7')
dimnames(station)[[3]]<-c('station1','station2')
print(station)
I would like to extract max value of win_3 which I called Max_3Days through spring season (i.e, month 3,4 and 5) of each year for each station and specify the corresponding value of day and month (either 3,4 or 5).
The same thing for min value, I want to extract it from win_7 which I called Min_7Days through summer season (i.e, month 6,7 and 8) of each year for each station and specify the corresponding value of month (either 6,7 or 8) and day
I would like to keep the result in array format if it possible.
The result should be like this:
, , 1
Year Month day Max_3Days Year Month Day Min_7Days
[1,] 2012 3 15 2800 2012 6 1 400
[2,] 2013 4 2 2730 2013 6 4 100
, , 2
Year Month day Max_3Days Year Month Day Min_7Days
[1,] 2012 4 15 2800 2012 7 10 250
[2,] 2013 5 2 2750 2013 7 14 271
I did specify spring and summer season and find the max, min values when I was having only one station as a data frame format, I want to do this for about 70 station in a (matrix) of an array format, and I want to keep the result in an array:
In case of data frame (only one station):
Summer<-station[which(station$month>"5"&station$month<"9"),]
Minima<-ddply(Summer, ~ year, summarise, month=month[which.min(win_7)],day=day[which.min(win_7)], Min_7Days =min(win_7, na.rm = TRUE))
Spring<-station[which(station$month>"2"&station$month<"6"),]
Maxima<-ddply(Spring, ~ year, summarise, month=month[which.max(win_3)],day=day[which.max(win_3)], Max_3Days =max(win_3, na.rm = TRUE))
Any suggestion would be appreciated!!
dputto show the example dataset - akrun