[R] conversion error from numeric to factor in raster: Error in 1:ncol(r) : argument of length 0, r command: as.factor()

David L Carlson dcarlson at tamu.edu
Tue May 6 20:27:21 CEST 2014


Does

values(r) <- as.factor(1:ncell(r))

do what you want?

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Stefan Schmidt
Sent: Tuesday, May 6, 2014 11:22 AM
To: r-help at r-project.org
Subject: [R] conversion error from numeric to factor in raster: Error in 1:ncol(r) : argument of length 0, r command: as.factor()

Hello together,

I was wondering how I can solve the following conversion problem of a 
raster file: when I try to convert the values from the raster (r) from 
numeric into a factor via as.factor(r) always the error appears: "Error 
in 1:ncol(r) : argument of length 0".

r <- raster(ncol=5, nrow=5)
values(r) <- 1:ncell(r)
as.factor(r)

Urgently I have to figure out how to convert a numeric raster into a 
factor raster for a predict() calculation within the raster package.

Every hint is very welcome!

Best,

Stefan

-- 
********************************************************************
Stefan Schmidt

Abteilung Landschaftsökologie/
Department Computational Landscape Ecology
Helmholtz-Zentrum für Umweltforschung GmbH – UFZ/
Helmholtz Centre for Environmental Research – UFZ
Permoserstraße 15 / 04318 / Leipzig
Phone: +49 341 235 - 1056
Fax: +49 341 235 - 1939
Email: stefan.schmidt at ufz.de
WWW: http://www.ufz.de

Sitz der Gesellschaft: Leipzig
Registergericht: Amtsgericht Leipzig, Handelsregister Nr. B 4703
Vorsitzender des Aufsichtsrats: MinDirig Wilfried Kraus
Wissenschaftlicher Geschäftsführer: Prof. Dr. Georg Teutsch
Administrative Geschäftsführerin: Dr. Heike Graßmann

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


More information about the R-help mailing list