[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-389902-105":3,"detail-sidebar-cat-0-en-105":81,"doc-detail-389902-en":130},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":74,"head_meta":76,"extra_data":78,"updated_unix":80},105,"en","collapse-advanced-and-fast-data-transformation-with-collapse-cheat-sheet","collapse - Advanced and Fast Data Transformation with collapse - CHEAT SHEET","","Advanced and Fast Data Transformation with collapse provides a concise guide to the collapse package for C/C++-based statistical operations in R. It supports grouped, weighted, time series, panel data, and recursive computations with efficient vectorization across rows and columns. The cheat sheet explains reference-based row/column arithmetic, in-place transformation via TRA/setTRA, and fast statistical functions such as means, medians, modes, minima, maxima, quantiles, ranges, and distances. It also covers core workflows for applying functions by groups and building GRP() objects for optimized grouping and ordering.",{"@graph":14,"@context":73},[15,34,56],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/document/","Document",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/document/technology/","Technology",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/document/collapse-advanced-and-fast-data-transformation-with-collapse-cheat-sheet/389902/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/collapse-advanced-and-fast-data-transformation-with-collapse-cheat-sheet/389902.png","ImageObject",300,407,{"name":42,"@type":43},"EvelynWrites","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-10-11","2026-09-25",true,{"@type":52,"interactionType":53,"userInteractionCount":55},"InteractionCounter",{"@type":54},"ViewAction",8,{"@type":57,"mainEntity":58},"FAQPage",[59,65,69],{"name":60,"@type":61,"acceptedAnswer":62},"What is the collapse package used for in R?","Question",{"text":63,"@type":64},"collapse enables advanced statistical operations in R, including grouped, weighted, time series, panel data, and recursive computations, using efficient low-level vectorizations across groups and columns.","Answer",{"name":66,"@type":61,"acceptedAnswer":67},"How do %cr% and %rr% differ in collapse?",{"text":68,"@type":64},"%cr% performs column-wise sweeping arithmetic, while %rr% performs row-wise sweeping arithmetic on vectors, matrices, data frames, or lists.",{"name":70,"@type":61,"acceptedAnswer":71},"How does TRA/setTRA modify data during grouped transformations?",{"text":72,"@type":64},"TRA generalizes row-wise operations to grouped statistics by sweeping or replacing based on computed STATS and FUN. Setting set=TRUE (or using setTRA) performs the transformation by reference in place.","https://schema.org",{"og:url":32,"og:type":75,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":77,"canonical":32},"index,follow",{"doc_id":79,"site_id":7},389902,1790882656,{"code":4,"msg":82,"data":83},"success",[84,88,92,96,101,105,110,114,119,122,126],{"id":22,"doc_module":4,"doc_module_name":25,"category_name":85,"show_sort_weight":86,"slug":87},"Story & Novel",90,"story-novel",{"id":26,"doc_module":4,"doc_module_name":25,"category_name":89,"show_sort_weight":90,"slug":91},"Literature",80,"literature",{"id":33,"doc_module":4,"doc_module_name":25,"category_name":93,"show_sort_weight":94,"slug":95},"Exam",70,"exam",{"id":97,"doc_module":4,"doc_module_name":25,"category_name":98,"show_sort_weight":99,"slug":100},5,"Comic",60,"comic",{"id":102,"doc_module":4,"doc_module_name":25,"category_name":29,"show_sort_weight":103,"slug":104},6,50,"technology",{"id":106,"doc_module":4,"doc_module_name":25,"category_name":107,"show_sort_weight":108,"slug":109},7,"Healthcare",40,"healthcare",{"id":55,"doc_module":4,"doc_module_name":25,"category_name":111,"show_sort_weight":112,"slug":113},"Research & Report",30,"research-report",{"id":115,"doc_module":4,"doc_module_name":25,"category_name":116,"show_sort_weight":117,"slug":118},9,"Religion & Spirituality",20,"religion-spirituality",{"id":117,"doc_module":4,"doc_module_name":25,"category_name":120,"show_sort_weight":117,"slug":121},"World Cup","world-cup",{"id":123,"doc_module":4,"doc_module_name":25,"category_name":124,"show_sort_weight":123,"slug":125},10,"Lifestyle","lifestyle",{"id":127,"doc_module":4,"doc_module_name":25,"category_name":128,"show_sort_weight":97,"slug":129},19,"General","general",{"code":4,"msg":82,"data":131},{"doc_id":79,"user_id":132,"nickname":42,"user_avatar":133,"doc_module":4,"category_id":102,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":55,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":26,"language":139,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":140,"faqs":141,"seo_title":142,"seo_description":12,"update_tm":143,"read_time":97},687212989558,"https://ap-avatar.wpscdn.com/davatar_a8503ba1806abce46bf441b54a3ca4cd","Advanced and Fast Data Transformation with collapse : : CHEAT SHEET  \nIntroduction  \ncollapse is a C/C++ based package supporting advanced (grouped, weighted, time series, panel data and recursive) statistical operations in R, with very efficient low-level vectorizations across both groups and columns.  \nIt also offers a flexible, class-agnostic, approach to data transformation in R: handling matrix and data frame based objects in a uniform, attribute preserving, way, and ensuring seamless compatibility with base R, dplyr / (grouped) tibble, data.table, xts/zoo, sf, and plm classes for panel data.  \ncollapse provides full control to the user for statistical programming-with several ways to reach the same outcome and rich optimization possibilities. It is globally configurable using set collapse() which includes algorithm defaults, multithreading, and the exported namespace (see below) .  \nCalling help(\"collapse-documentation\") brings up a detailed documentation, which is also available online. See also the fastverse package/project for a recommended set of complimentary packages and easy package management.  \nRow/Column Arithmetic (by Reference)  \nColumn-wise sweeping out of vectors/matrices/DFs/lists %cr%,%c+%,%c-%,%c*%,%c/% e.g. Z = X %c/% rowSums(X)  \nRow-wise sweeping vectors from vectors/matrices/DFs/lists %rr%,%r+%,%r-%,%r*%,%r/% e.g. Z = X %r/% colSums(X)  \nStandard (column-wise) math by reference (returns invisibly)%+=%,%-=%,%*=%,%/=% e.g. X %-=% rowSums(X)  \nSame thing, also supports row-wise operations by referencesetop(X, \"/\", rowSums(X))  \nsetop(X, \"/\", colSums(X), rowwise = TRUE)  \nTransform Data by (Grouped) Replacing or Sweeping out Statistics (by Reference)  \nA generalisation of rowwise operations, that also supports sweeping by groups e.g. aggregate statistics  \nTRA(x, STATS, FUN = \"-\", g = NULL, set = FALSE) setTRA(x, STATS, FUN = \"-\", g = NULL)  \nx vector, matrix, or (grouped) data frame / list  \nSTATS statistics matching (columns of) x (i.e. aggregated vector, matrix or data frame / list)  \nFUN integer/string indicating transformation to perform: Int. String Description  \n0 \"replace NA\" replace missing values in x  \n1 \"replace fill\" replace data and missing values in x  \n2 \"replace\" replace data but preserve missing values in x  \n3 \"- \" subtract: x-STATS(g)  \n4 \"-+\" x-STATS(g) + fmean(STATS, w = GRPN)  \n5 \"/\" divide: x / STATS(g)  \n6 \"%\" compute percentages: x * 100/STATS(g)  \n7 \"+\" add: x + STATS(g)  \n8 \"*\" multiply: x * STATS(g)  \n9 \"%%\" modulus: x %% STATS(g)  \n10 \"-%%\" subtract modulus: x-x %% STATS(g) g [optional](list of) vectors / factors or GRP() object  \nset TRUE transforms x by reference. setTRA is equivalent to invisible(TRA( . . . , set = TRUE))  \nFast Statistical Functions  \nFast functions to perform column–wise grouped and weighted computations on matrix-like objects  \nfmean, fmedian, fmode, fsum, fprod, fsd, fvar,  \nfmin, fmax, fnth, ffirst, flast, fnobs, fndistinct  \nSyntax  \nFUN(x, g = NULL, [w = NULL], TRA = NULL,  \n[na.rm = TRUE], use.g.names = TRUE,  \n[drop = TRUE], [nthreads = 1L])  \nx vector, matrix, or (grouped) data frame / list g [optional](list of) vectors / factors or GRP() object w [optional] vector of (frequency) weights  \nTRA [optional] operation to transform data with computed statistics (see FUN argument to TRA() and Examples)  \ndrop drop matrix / data frame dimensions. default TRUE  \nExamples  \nfmean(AirPassengers) \\# Vector \\#\\# [1] 280 .2986  \nfmean(AirPassengers, w = cycle(AirPassengers)) \\# Weighted mean \\#\\# [1] 284.3397  \nfmean(EuStockMarkets) \\# Matrix  \n\\#\\# DAX SMI CAC FTSE  \n\\#\\# 2530 .657 3376 .224 2227 .828 3565 .643  \nfmean(airquality) \\# Data Frame (use drop = FALSE to keep frame)  \n\\#\\# Ozone Solar.R Wind Temp Month Day  \n\\#\\# 42 .129310 185 .931507 9 .957516 77 .882353 6 .993464 15 .803922 fmean(iris[1:4], g = iris$Species) \\# Grouped  \n\\#\\# Sepal .Length Sepal .Width Petal .Length Petal .Width  \n\\#\\# setosa 5.006 3.428 1.462 0.246  \n\\#\\# versicolor 5.936 2.7","cbCaiqsx3fwxGLGw","https://ap.wps.com/l/cbCaiqsx3fwxGLGw","pdf",379436,"English","# Introduction\n# Row/Column Arithmetic (by Reference)\n# Transform Data by (Grouped) Replacing or Sweeping out Statistics (by Reference)\n# Fast Statistical Functions\n# Other Statistical Functions\n# Basic Computing with R Functions\n# Grouping and Ordering","[{\"question\":\"What is the collapse package used for in R?\",\"answer\":\"collapse enables advanced statistical operations in R, including grouped, weighted, time series, panel data, and recursive computations, using efficient low-level vectorizations across groups and columns.\"},{\"question\":\"How do %cr% and %rr% differ in collapse?\",\"answer\":\"%cr% performs column-wise sweeping arithmetic, while %rr% performs row-wise sweeping arithmetic on vectors, matrices, data frames, or lists.\"},{\"question\":\"How does TRA/setTRA modify data during grouped transformations?\",\"answer\":\"TRA generalizes row-wise operations to grouped statistics by sweeping or replacing based on computed STATS and FUN. Setting set=TRUE (or using setTRA) performs the transformation by reference in place.\"}]","collapse - Advanced and Fast Data Transformation with collapse - CHEAT SHEET | PDF",1790328318]