Skip to content
Prev 366843 / 398502 Next

(no subject)

How you proceed depends on how consistent the data are and on what you want to do with those sets of three months after you have identified them.

One approach is to create a matrix where each row contains the values corresponding to the "second previous", "previous", and "current" months data, respectively using the embed() function. The first two rows would be incomplete because the earlier data are missing there:

d3 <- embed( dta$MEI )

with which you could compute whatever metric you wanted. For example you could compute rolling means:

dta$MEImeans <- rowMeans( d3 )

If your data have missing rows you might need to use the aggregate or merge functions instead. 

For specific layouts of data or metrics you can find specialized functions in various packages. You might want to search using the R "sos" package or Google for your analysis method of choice.