Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ingmarboeschen/mongotable
Create one and two dimensional frequency tables
https://github.com/ingmarboeschen/mongotable
frequency-table mongodb r
Last synced: 27 days ago
JSON representation
Create one and two dimensional frequency tables
- Host: GitHub
- URL: https://github.com/ingmarboeschen/mongotable
- Owner: ingmarboeschen
- License: gpl-3.0
- Created: 2024-11-11T09:20:44.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2024-11-11T09:45:15.000Z (about 1 month ago)
- Last Synced: 2024-11-11T10:27:25.596Z (about 1 month ago)
- Topics: frequency-table, mongodb, r
- Language: R
- Homepage:
- Size: 138 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mongoTable::mongoTable()
This function generates one-dimensional and two-dimensional frequency tables from data stored in a MongoDB database. Rather than retrieving the entire dataset through a `find()` operation, this function leverages MongoDB's aggregation capabilities to compile frequency data directly on the server, followed by post-processing in R.
## Usage
```R
mongoTable(connection, x, y = NULL, query = "{}",lowerize = FALSE, limit = NULL, sort = FALSE, decreasing = TRUE)
```## Arguments
| Name | Description|
| :--- | :--- |
| connection | character. A mongo connection object initiated with mongolite::mongo().|
| x | character. A field variable for which frequencies should be counted.|
| y | character. An optional second field variable for which frequencies should be counted.|
| query | character. An optional MongoDB query for data subset selection (e.g.: ’{\"year\": 2024}’). |
| lowerize | logical. All levels in one dimensional tables will be lowerized. |
| limit | integer. Defines the maximum length/dimensions of output.|
| sort | logical. If TRUE, the output is sorted by frequency.|
| decreasing | logical. If TRUE and sort==TRUE, the output is returned with decreasing frequencies. If TRUE and sort==FALSE, level names are returned in decreasing manner.|## Installation with the devtools package
```R
if(require(devtools)!=TRUE) install.packages("devtools")
devtools::install_github("ingmarboeschen/mongoTable")
```## Examples
```R
## use mongolite::mongo() to connect to a MongoDB instance (demo server)
mon <- mongolite::mongo("mtcars", url = "mongodb+srv://readwrite:[email protected]/test")
if(mon$count() > 0) mon$drop()
mon$insert(mtcars)
stopifnot(mon$count() == nrow(mtcars))## Create a one-dimensional frequency table
# for all x
mongoTable(connection = "mon", x = "cyl")# for all x matching a query (cars with mpg greater than 20)
mongoTable(connection="mon", x="cyl", query = '{\"mpg\": {\"$gt": 20}}')## Create a two-dimensional frequency table
# for all x and y
mongoTable(con = "mon", x = "cyl", y = "gear")# for all x and y matching a query (cars with mpg greater than 20)
mongoTable(con="mon", x = "cyl", y = "gear", query = '{\"mpg\": {\"$gt": 20}}')```