Data & Workflow · Tables, pipelines, and notebooks
phplyr
A PHP port of the Tidyverse's dplyr and tidyr.
composer require phpstats/phplyr
- Requires
- phibble (installed by Composer) PDO extension mbstring extension
- Optional
- phit extension (lm(), glm(), lmer(), and glmer(), and native descriptive statistics) phpolars extension (phibble's PolarsTable backend) intl extension (janitor-matching transliteration in clean_names() and make_clean_names()) PDO driver for SQLite, PostgreSQL, or MySQL (database tables through Phibble\tbl())
- Platforms
- Linux macOS
phplyr covers most of dplyr and tidyr. Each function returns a closure, so steps compose with the PHP 8.5 pipe operator.
The dplyr side includes the single-table functions, mutating and filtering joins, set operations, window functions such as lag(), lead(), and row_number(), and across() with tidyselect-style selectors.
The tidyr side includes pivot_longer(), pivot_wider(), separate and unite functions, nesting, and functions for completing and filling missing values.
Summary helpers such as n(), mean(), sd(), and quantile() follow R conventions for missing values and use phit when the extension is loaded. Model formulas such as monthly_rent ~ area_m2 + neighborhood will fit models through phit.
Example
$schools = DataFrame::fromCsv('schools.csv');
echo $schools |>
filter(fn ($r) => $r->study_hours >= 5) |>
group_by('school') |>
summarize(students: n(), avg_score: mean('score'), sd_score: sd('score')) |>
arrange(desc('avg_score')) |>
head(5);
$schools = DataFrame::fromCsv('schools.csv');
echo phplyr($schools)
->filter(fn ($r) => $r->study_hours >= 5)
->groupBy('school')
->summarize(students: n(), avg_score: mean('score'), sd_score: sd('score'))
->arrange(desc('avg_score'))
->head(5);
Output · 5 × 4
school students avg_score sd_score
<chr> <int> <dbl> <dbl>
1 school-07 14 86.9 6.32
2 school-06 20 80.9 8.90
3 school-02 12 79.7 8.22
4 school-09 11 79.3 6.67
5 school-11 13 77.6 7.31