cbailiss / pivottabler

Create Pivot Tables natively in R

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sort Column by other column

Stephonomon opened this issue · comments

Hi, is it possible to use an order by for the addRowDataGroups line? For example, I want to have a group for Months (January-December) and to have them sorted by their number order (1-12). It's doing alphabetical at the moment.

pt$addRowDataGroups("TOC", dataSortOrder="desc")

The best approach here is to set the data group to be based on a date or POSIXct column from a data frame (as opposed to being based on a text column). The values will then sort into the correct order in the pivot table. You can then format the values to display in a more text-friendly way.
An example of doing this can be found under the Formatting Data Groups heading in the Data Groups vignette:
https://cran.r-project.org/web/packages/pivottabler/vignettes/v02-datagroups.html

More general sorting options (including sorting by a calculation value) are described on the same page under the Sorting data groups heading.
https://cran.r-project.org/web/packages/pivottabler/vignettes/v02-datagroups.html