完整程序:
library(glmnet)
x=matrix(rnorm(100*20),100,20)
y=rnorm(100)
cv.fit=cv.glmnet(x,y)
coef(cv.fit)
结果显示:
21 x 1 sparse Matrix of class "dgCMatrix"
1
(Intercept) 0.05693593
V1 0.00000000
V2 0.00000000
V3 0.00000000
V4 0.00000000
V5 0.00000000
V6 0.00000000
V7 0.00000000
V8 0.00000000
V9 0.00000000
V10 0.00000000
V11 0.00000000
V12 0.00000000
V13 0.00000000
V14 0.00000000
V15 0.00000000
V16 0.00000000
V17 0.00000000
V18 0.00000000
V19 0.00000000
V20 0.00000000
>
如何讲结果作为length=21的向量提取出来呢?