[R] Counting number of rain

Dan D ddalthorp at usgs.gov
Tue Sep 8 16:37:05 CEST 2015

Try the following:

## step 1: write raw data to an array
# entering the numbers (not the 'year' etc. labels) into R as a vector after

# convert the vector into a 2-d array with 4 columns (year, month, day,

## step 2: create a dataframe to store and display the results
ans<-data.frame(array(dim=c(nyr,12))) # a dataframe for storing the results

# step 3: calculate
for (yi in 1:nyr){ # loop through the years...
  for (mi in 1:12){ # ...and the months
     ans[yi,mi]<-sum(junk[junk[,1]==yrs[yi] & junk[,2]==mi,4]>0.000001) #
count the rainy days by
     # first subsetting the junk array by rows that match the given year and
month and sum

Does that help?

- Dan

View this message in context: http://r.789695.n4.nabble.com/Counting-number-of-rain-tp4712007p4712011.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list