Error while using as.factor function

87 views
Skip to first unread message

Milica Rankovic

unread,
Apr 23, 2021, 8:00:41 AM4/23/21
to Maxent
Dear colleagues, 
I tried to classify variable from my raster stack of predictor variables as a factor via function:
predictors[,'var1'] = as.factor(predictors[,'var1']) 
but R showed me this kind of mistake:
Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'as.factor': object of type 'S4' is not subsettable
 Did someone else have a similar problem and how did you solve it?

Thank you and best regards,
Milica

Bede-Fazekas Ákos

unread,
Apr 23, 2021, 8:15:31 AM4/23/21
to max...@googlegroups.com
Dear Milica,
RasterStack is not subsettable with the [i, j] operator but with [[i]] operator. So try this:
predictors[['var1']] = as.factor(predictors[['var1']])
HTH,
Ákos Bede-Fazekas
--
You received this message because you are subscribed to the Google Groups "Maxent" group.
To unsubscribe from this group and stop receiving emails from it, send an email to maxent+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/maxent/3cd72366-0493-4b41-843d-1d97ebde7d5dn%40googlegroups.com.

Milica Rankovic

unread,
Apr 23, 2021, 8:29:38 AM4/23/21
to max...@googlegroups.com
Dear Akos, 

thank you very much for helping, I will try it,

Best regards,
Milica

You received this message because you are subscribed to a topic in the Google Groups "Maxent" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/maxent/JfkLrN-2xb0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to maxent+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/maxent/b304f952-9e58-6458-5a72-df6dc9df68f0%40gmail.com.


--

MSc Milica Ranković, PhD student

Research Assistant 
University of Novi Sad
Faculty of Sciences
Department of Biology and Ecology
Trg Dositeja Obradovica 2
21000 Novi Sad
Serbia


Reply all
Reply to author
Forward
0 new messages