任何人都可以帮助我重命名 的列名model.matix
吗?
我一直在尝试重命名我的列:
colnames(model.matrix(reg))[1] <- c("Intercept")
但我收到错误消息:
could not find function "model.matrix<-"
这是model.matrix
对象:
model.matrix.default(reg)
xxXB(Intercept) xxXBproductPageViews xxXBqty_order xxXBLag.sales
2 1.782842 2352.032 1.804487 303.0831
4 1.782842 1569.158 1.799786 369.0831
5 1.782842 2541.884 1.806206 434.7506
6 1.782842 2932.289 1.811827 414.7104
7 1.782842 2670.780 1.798207 360.4423
8 1.782842 2694.579 1.793033 291.9571
9 1.782842 5435.900 1.791143 325.7292
10 1.782842 10727.969 1.807148 602.7453
11 1.782842 12711.044 1.826717 1130.3189
12 1.782842 10774.425 1.808426 1694.6620
13 1.782842 8597.127 1.789496 1611.1204
14 1.782842 7647.235 1.789358 1161.2223
15 1.782842 5538.071 1.798733 979.3913
16 1.782842 4240.954 1.798549 813.5173
17 1.782842 3890.973 1.787179 668.3082
18 1.782842 4086.364 1.816897 563.1715
19 1.782842 4878.903 1.815232 552.4128
20 1.782842 3999.407 1.787328 612.4691
21 1.782842 3349.887 1.875233 526.7774
22 1.782842 5394.895 1.891263 599.2761
23 1.782842 4682.374 1.817970 1290.7023
24 1.782842 3346.345 1.805635 1057.0534
25 1.782842 3106.214 1.839484 638.3726
26 1.782842 4559.091 1.878944 611.1822
attr(,"assign")
[1] 1 1 1 1
上面的矩阵是lm
方程的矩阵,称为reg
。现在如何更改列名 model.matrix
?