[R] lag function row name with

John m|@ojpm @end|ng |rom gm@||@com
Mon Mar 25 08:44:34 CET 2019


Hi,

   I have a dataset whose row names corresponds to months. When I apply lag
function (dplyr package) on this dataset, I get NAs with warning messages.
Is there any lag function that carries out the lag but keep the row names?
   I will have two datasets. The dates of the datasets are not exactly the
same, and I want to find out the correlation for the overlapping period.

   Thanks,


> temp
         oil95
1981M01 103.27
1981M02 107.92
1981M03 110.26
1981M04 110.26
1981M05 110.11
1981M06 109.93
1981M07 109.93
1981M08 109.93
1981M09 109.93
1981M10 109.93

> dplyr::lag(temp, 2)
        oil95
1981M01    NA
1981M02  <NA>
1981M03  <NA>
1981M04  <NA>
1981M05  <NA>
1981M06  <NA>
1981M07  <NA>
1981M08  <NA>
1981M09  <NA>
1981M10  <NA>
Warning message:
In format.data.frame(x, digits = digits, na.encode = FALSE) :
  corrupt data frame: columns will be truncated or padded with NAs
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list