spq_tally: Count the observations

View source: R/spq_tally.R

spq_tallyR Documentation

Count the observations

Description

These functions are inspired by dplyr::count() and dplyr::tally(). spq_tally() assumes you've already done the grouping.

Usage

spq_tally(.query, sort = FALSE, name = "n")

spq_count(.query, ..., sort = FALSE, name = "n")

Arguments

.query

a list with elements of the query

sort

If TRUE, will show the largest groups at the top. (like the sort argument of dplyr::tally())

name

Name for the count column (like the name argument of dplyr::tally())

...

variables by which to arrange (or SPARQL strings escaped with spq(), or strings, see examples)

Value

A query object

Examples

## Not run: 
spq_init() %>%
spq_add("?film wdt:P31 wd:Q11424") %>%
spq_mutate(narrative_location = wdt::P840(film)) %>%
spq_label(narrative_location) %>%
spq_tally(name = "n_films") %>%
spq_perform()

# the same with spq_count

spq_init() %>%
spq_add("?film wdt:P31 wd:Q11424") %>%
spq_mutate(narrative_location = wdt::P840(film)) %>%
spq_label(narrative_location) %>%
spq_count(name = "n_films") %>%
spq_perform()

# Now with grouping
spq_init() %>%
spq_add("?film wdt:P31 wd:Q11424") %>%
spq_mutate(narrative_location = wdt::P840(film)) %>%
spq_label(film, narrative_location) %>%
spq_group_by(narrative_location_label) %>%
spq_tally(sort = TRUE, name = "n_films") %>%
spq_perform()


# More direct with spq_count()
spq_init() %>%
spq_add("?film wdt:P31 wd:Q11424") %>%
spq_mutate(narrative_location = wdt::P840(film)) %>%
spq_label(film, narrative_location) %>%
spq_count(narrative_location_label, sort = TRUE, name = "n_films") %>%
spq_perform()

## End(Not run)

lvaudor/glitter documentation built on Jan. 30, 2024, 1:34 a.m.