chamex14
chamex14

Reputation: 1

How do i calculate the mean value of a specific day of a 30-year daily series?

I'm a beginner on R, and i have an array (a matrix lat-lon with steps on time) of daily accumulated precipitation from 01-JAN-1980 to 31-DEC-2010. What i want to do is to calculate the mean value of a specific point for a specific day of the year. For example: how do i calculate the mean value of a point (i,j) for 06-APR?

Upvotes: 0

Views: 527

Answers (1)

James King
James King

Reputation: 6385

You probably have a dataframe rather than an array, correct, or you could not mix numbers and strings (I'm assuming below that your date value is a string)?

First you can calculate the month and the day, where dt_str is the column containing your dates:

require(lubridate)
D <- day(strptime(dt_str, "%d-%b-%Y"))
M <- month(strptime(dt_str, "%d-%b-%Y"))

then take the average you want using subsetting:

mean(X[D == 6 & M == 4, i])

where i is the column you want to take the mean of.

Upvotes: 1

Related Questions