How to treat this kind of errors?

Hello I am using following data and ran some data operation. But it did not work well. Could give me some way of solving my errors? The error was..
Error in [<-.data.frame(*tmp*, , i, value = list()) :
new columns would leave holes after existing columns.
Thank you.

TG

DESCRIPTOR	FFR	Tbill	Tb1yr
1960Q1	3.93	3.87	4.57
1960Q2	3.7	2.99	3.87
1960Q3	2.94	2.36	3.07
1960Q4	2.3	2.31	2.99
1961Q1	2	2.35	2.87
1961Q2	1.73	2.3	2.94
1961Q3	1.68	2.3	3.01
1961Q4	2.4	2.46	3.1
1962Q1	2.46	2.72	3.21
1962Q2	2.61	2.72	3.02
1962Q3	2.85	2.84	3.18

> DATA = data[ -1, ]
> for (i in 1:ncol(DATA)) {
+    DATA[,i]=diff(data[,i])
+ }
Error in `[<-.data.frame`(`*tmp*`, , i, value = list()) : 
  new columns would leave holes after existing columns
>

Are you trying to import those data from somewhere else?

Thank you for your question!
No, I try to run my codes using the data.
I use some data named as DATA and try run this way.

DATA = data[-1,]
for (i in 1:ncol(DATA)) {
   DATA[,i]=diff(data[,i])
}

e.w = lm3$residuals
VAR(DATA,p=1,exogen=e.w[-length(e.w)])

Any ideas will be welcomed and appreciated!

TG

You cant apply diff() to all columns in your data frame since it contains a non-numeric column (i.e. "DESCRIPTOR"). If you start from column 2 the code works

data <- data.frame(stringsAsFactors=FALSE,
   DESCRIPTOR = c("1960Q1", "1960Q2", "1960Q3", "1960Q4", "1961Q1", "1961Q2",
                  "1961Q3", "1961Q4", "1962Q1", "1962Q2", "1962Q3"),
          FFR = c(3.93, 3.7, 2.94, 2.3, 2, 1.73, 1.68, 2.4, 2.46, 2.61, 2.85),
        Tbill = c(3.87, 2.99, 2.36, 2.31, 2.35, 2.3, 2.3, 2.46, 2.72, 2.72,
                  2.84),
        Tb1yr = c(4.57, 3.87, 3.07, 2.99, 2.87, 2.94, 3.01, 3.1, 3.21, 3.02,
                  3.18)
)

DATA = data[ -1, ]
for (i in 2:ncol(DATA)) {
    DATA[,i]=diff(data[,i])
}
DATA
#>    DESCRIPTOR   FFR Tbill Tb1yr
#> 2      1960Q2 -0.23 -0.88 -0.70
#> 3      1960Q3 -0.76 -0.63 -0.80
#> 4      1960Q4 -0.64 -0.05 -0.08
#> 5      1961Q1 -0.30  0.04 -0.12
#> 6      1961Q2 -0.27 -0.05  0.07
#> 7      1961Q3 -0.05  0.00  0.07
#> 8      1961Q4  0.72  0.16  0.09
#> 9      1962Q1  0.06  0.26  0.11
#> 10     1962Q2  0.15  0.00 -0.19
#> 11     1962Q3  0.24  0.12  0.16

Created on 2019-10-16 by the reprex package (v0.3.0.9000)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.