I have a matrix with 24 time series which looks like:
Ta.f Ta.f Ta.f Ta.f
1995-10-13 04:00:00 13.6 13.6 13.6 13.6
1995-10-13 05:00:00 13.6 13.6 13.6 13.6
1995-10-13 06:00:00 13.6 13.6 13.6 13.6
1995-10-13 07:00:00 13.5 13.5 13.5 13.5
1995-10-13 08:00:00 13.5 13.5 13.5 13.5
I would like to use the apply() function to every column to difference according the index of the column. So column 1 needs diff(x,), column 2 needs diff(x,lag=2) and so on. What I have done is that:
trans_temp <- apply(temp_mat,MARGIN=2,diff)
Which returns a matrix in which all time series are differenced once. Any recommendation?