【发布时间】:2017-09-11 00:19:34
【问题描述】:
我整天都在和这只野兽战斗。一方面它想要一个矩阵,另一方面它想要一个 data.frame,但它都不需要。请帮忙。
> Coffee <- raster("b2boolcafetst.rst")
> b <- raster("b2_dstcabtst.rst")
> c <- raster("b2_dstrdstst.rst")
> d <- raster("b2_dstfuentst.rst")
> e <- raster("b2_srtmtst.rst")
> fdf <- as.data.frame(stack(Coffee, b, c, d, e))
> str(fdf)
'data.frame': 296856 obs. of 5 variables:
$ b2boolcafetst: num 0 0 0 0 0 0 0 0 0 0 ...
$ b2_dstcabtst : num 9512 9482 9452 9422 9392 ...
$ b2_dstrdstst : num 1980 1980 1981 1982 1984 ...
$ b2_dstfuentst: num 5155 5134 5112 5091 5070 ...
$ b2_srtmtst : num 975 980 984 991 998 ...
> fdfdm <- as.matrix(fdf)
> str(fdfdm)
num [1:296856, 1:5] 0 0 0 0 0 0 0 0 0 0 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:5] "b2boolcafetst" "b2_dstcabtst" "b2_dstrdstst" "b2_dstfuentst" ...
> fdfmod <- glm(Coffee ~ b + c + d + e, family=binomial(link='logit'),
+ data=fdf)
Error in model.frame.default(formula = Coffee ~ b + c + d + e, data = fdf, :
object is not a matrix
> fdfmod <- glm(Coffee ~ b + c + d + e, family=binomial(link='logit'),
+ data=fdfdm)
Error in model.frame.default(formula = Coffee ~ b + c + d + e, data = fdfdm, :
'data' must be a data.frame, not a matrix or an array
>
【问题讨论】:
-
将
Coffee ~ b + c + d + e替换为对应的名称b2boolcafetst、b2__dstcabtst等