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
______________________________________________
[email protected] 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.