Closed sriramab closed 5 months ago
Since the Group1
and Field1
objects in the script generate character objects then the special syntax of the .data
pseudo object can be used. With the following .data[[var]]
structure. Your script should be written as follows:
##Issue133=name
##Layer=vector
##GroupsFromTable=Field Layer
##VariableToSummarise=Field Layer
##Aggregated=Output vector
library(dplyr)
Aggregated <- Layer %>%
dplyr::group_by(.data[[GroupsFromTable]]) %>%
dplyr::summarise(sum_f1 = sum(.data[[VariableToSummarise]], na.rm=T))
Thank you. Your solution works.
Hi For reasons of comfort and legacy code, I use dplyr and the tidyverse style of R coding. I am trying to write a r script inside qgis. And I would like to do some summary using
dplyr::group_by
, and thendplyr::summarize
. I am currently using the following syntaxwhere Group1 is the grouping variable and Field1 is the numeric field I would like summarize (sum) for each group. As dplyr uses variable style column names instead of pure string column names, I am finding it difficult to use dplyr like syntax in qgis-processing-r.
If you see for Group1 in my code, I also tried using the embrace{{}} and also tried the standard way of
[[
as you see in my summarize . both styles do not work.Please guide how I can use the dplyr style syntax in QGIS R scripts.