[R] Finding Rainfall Amount
    Jim Lemon 
    jim at bitwrit.com.au
       
    Wed Oct  8 11:09:02 CEST 2014
    
    
  
On Tue, 7 Oct 2014 07:25:49 PM Hafizuddin Arshad wrote:
> Dear R users,
> 
> I have this kind of data set which is part of my data:
> 
> ...
> 
> I would like to find the rainfall total for each month within a year. The
> result should be like in this form:
> 
> ...
> 
> where V1 until V12 as month and 1 until 80 as a years. How can I do 
this in
> R? 
Hi Arshad,
This might be what you want:
yearcorr<-min(raindat$Year)-1
years<-unique(raindat$Year)
rainmonth<-as.data.frame(matrix(0,nrow=2,ncol=12))
for(year in years) {
 for(month in 1:12) {
  if(any(raindat$Year==year&raindat$Month==month))
   rainmonth[year-yearcorr,month]<-
    mean(raindat$Rain[raindat$Year==year&raindat$Month==month],na.rm=TRUE)
 }
}
rownames(rainmonth)<-years
names(rainmonth)<-month.abb
Jim
    
    
More information about the R-help
mailing list