diff --git a/vignettes/polars.Rmd b/vignettes/polars.Rmd index 2f5d1f3b9..1d4d550d6 100644 --- a/vignettes/polars.Rmd +++ b/vignettes/polars.Rmd @@ -333,7 +333,7 @@ To go from long to wide, we use the `$pivot()` method. Here we pivot the data so that every subject takes its own column. ```{r} -indo_wide = indo$pivot(values = "conc", index = "time", columns = "Subject") +indo_wide = indo$pivot(values = "conc", index = "time", on = "Subject") indo_wide ``` @@ -341,7 +341,7 @@ To go from wide to long, we use the `$melt()` method. ```{r} # indo_wide$melt(id_vars = "time") # default column names are "variable" and "value" -indo_wide$melt(id_vars = "time", variable_name = "subject", value_name = "conc") +indo_wide$unpivot(index = "time", variable_name = "subject", value_name = "conc") ``` Basic functionality aside, it should be noted that `$pivot()` can perform @@ -356,7 +356,7 @@ different combinations of transmission type (`am`) and engine shape (`vs`)? dat$pivot( values = "mpg", index = c("am", "vs"), - columns = "cyl", + on = "cyl", aggregate_function = "median" # aggregating function ) ``` diff --git a/vignettes/userguide.Rmd b/vignettes/userguide.Rmd index 0e7857b82..fe988a4d9 100755 --- a/vignettes/userguide.Rmd +++ b/vignettes/userguide.Rmd @@ -271,77 +271,76 @@ dataset$ collect() ``` -````{comment} -```{r} -compute_age = function() 2021 - pl$col("birthday")$dt$year() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -avg_birthday = function(gender) { - compute_age()$filter(pl$col("gender") == gender)$mean()$alias(sprintf("avg %s birthday", gender)) -} - -q = ( - dataset$lazy()$ - group_by("state")$ - agg( - avg_birthday("M"), - avg_birthday("F"), - (pl$col("gender") == "M")$sum()$alias("# male"), - (pl$col("gender") == "F")$sum()$alias("# female") - )$ - limit(5) -) -q$collect() - -# -# get_person <- function() pl$col("first_name") + pl$lit(" ") + pl$col("last_name") -# q = ( -# dataset$lazy() -# $sort("birthday", descending=True) -# $group_by(["state"]) -# $agg( -# [ -# get_person()$first()$alias("youngest"), -# get_person()$last()$alias("oldest"), -# ] -# ) -# $limit(5) -# ) -# q$collect() -# -# get_person <- function() pl$col("first_name") + pl$lit(" ") + pl$col("last_name") -# q = ( -# dataset$lazy() -# $sort("birthday", descending=True) -# $group_by(["state"]) -# $agg( -# [ -# get_person()$first()$alias("youngest"), -# get_person()$last()$alias("oldest"), -# get_person()$sort()$first()$alias("alphabetical_first"), -# ] -# ) -# $limit(5) -# ) -# q$collect() -# -# q = ( -# dataset$lazy() -# $sort("birthday", descending=True) -# $group_by(["state"]) -# $agg( -# [ -# get_person()$first()$alias("youngest"), -# get_person()$last()$alias("oldest"), -# get_person()$sort()$first()$alias("alphabetical_first"), -# pl$col("gender")$sort_by("first_name")$first()$alias("gender"), -# ] -# ) -# $sort("state") -# $limit(5) -# ) -# q$collect() -``` -```` ## Folds @@ -451,8 +450,6 @@ df$sort("Type 1")$select( # List context and row wise computations ````{comment} - -``` grades = pl$DataFrame( "student" = c("bas", "laura", "tim", "jenny"), "arithmetic" = c(10, 5, 6, 8), @@ -520,7 +517,7 @@ out = df$select( ) print(out) ``` -```` + # R examples