dataframe - R is not a matrix, but it won't take a data.frame either -


i have been fighting beast day. on 1 hand wants matrix, , on other wants data.frame, , yet take neither. please help.

> 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 not 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 data.frame, not matrix or array >  

this error tends occur when you're referencing objects/variables not columns in data frame or matrix you're using. replacing "b + c + d + e" column names in data should solve this. try this:

glm(coffee ~ b2_dstcabtst + b2_dstrdstst + b2_dstfuentst + b2_srtmtst,      family=binomial(link='logit'), data=fdf) 

if you'll using columns in data though, appears case here, can use:

glm(coffee ~ ., family=binomial(link='logit'), data=fdf) 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -