For what it's worth, if we define Rsql as the following script:
#!/usr/bin/env Rscript
library(sqldf, quietly=TRUE)
statement <- commandArgs(TRUE)
a <- read.table(file("stdin"), header=TRUE)
print(sqldf(statement))
then we can call ps -Ao user | Rsql 'select USER, count(*) as nprocesses from a group by USER limit 5'
to get the output USER nprocesses
1 avahi 2
2 colord 1
3 daemon 1
4 marcle 136
5 messagebus 1