[Qgis-user] QGIS-R

Alex Mandel tech_dev at wildintellect.com
Thu Jun 11 00:33:45 PDT 2015


On 06/10/2015 09:12 PM, Daniel Torres wrote:
> Hi every one, I'm having a hard time with Sextante and R. I'm trying to
> make a little script to calculate the sum of a variable per cathegory, the
> script runs in R, but I can't understand how to make it work in QGIS...
> 
> I haven't found many examples on QGIS-R, and the few ones use only one
> variable...
> 
> Any help is welcome (any documentation or examples are very welcome),
> Thanks,
> Daniel
> 
> 
> 
> 
> ##Basic statistics=group
> ##Layer=vector
> ##valores=Field Layer
> ##categorias=Field Layer
> valores<-Layer[[valores]]
> categorias<-Layer[[categorias]]
> catego<-as.factor(categorias)
> catego_unicos<-unique(catego)
> suma<-NA;suma<-data.frame(suma)
> for(i in 1:length(catego_unicos)){
> suma[i,1]<-sum(valores[catego==catego_unicos[i]])
> }
> colnames(suma)<-"suma"
> rownames(suma)<-catego_unicos
>> suma
> 
> 
> 

Here's a whole bunch of working examples. These can all be installed
from the download script in Processing now (under the R section).
https://github.com/qgis/QGIS-Processing/tree/master/rscripts

I think you're missing a variable to return the answer with?

Enjoy,
Alex




More information about the Qgis-user mailing list