[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-1-en-105":3,"doc-seo-572989-105":53,"doc-detail-572989-en":126},{"code":4,"msg":5,"data":6},0,"success",[7,14,19,24,29,34,39,44,49],{"id":8,"doc_module":9,"doc_module_name":10,"category_name":11,"show_sort_weight":12,"slug":13},11,1,"Template","Presentations",90,"presentations",{"id":15,"doc_module":9,"doc_module_name":10,"category_name":16,"show_sort_weight":17,"slug":18},12,"Resumes",80,"resumes",{"id":20,"doc_module":9,"doc_module_name":10,"category_name":21,"show_sort_weight":22,"slug":23},14,"Invoices",70,"invoices",{"id":25,"doc_module":9,"doc_module_name":10,"category_name":26,"show_sort_weight":27,"slug":28},15,"Posters",60,"posters",{"id":30,"doc_module":9,"doc_module_name":10,"category_name":31,"show_sort_weight":32,"slug":33},16,"Social Media",50,"social-media",{"id":35,"doc_module":9,"doc_module_name":10,"category_name":36,"show_sort_weight":37,"slug":38},17,"Forms",40,"forms",{"id":40,"doc_module":9,"doc_module_name":10,"category_name":41,"show_sort_weight":42,"slug":43},18,"Letters",30,"letters",{"id":45,"doc_module":9,"doc_module_name":10,"category_name":46,"show_sort_weight":47,"slug":48},21,"Paper Templates",5,"papers-templates",{"id":50,"doc_module":9,"doc_module_name":10,"category_name":51,"show_sort_weight":4,"slug":52},158,"General","general-158",{"code":4,"msg":54,"data":55},"ok",{"site_id":56,"language":57,"slug":58,"title":59,"keywords":60,"description":61,"schema_data":62,"social_meta":119,"head_meta":121,"extra_data":123,"updated_unix":125},105,"en","data-transformation-with-datatable-cheat-sheet","Data Transformation with data.table - Cheat Sheet","","Data Transformation with data.table provides a fast, memory-efficient approach to transforming data in R using concise data.table syntax. It explains core concepts such as dt[i, j, by], creating data.tables from scratch or converting existing data.frames, and manipulating columns with extraction, summarization, and computed expressions. The cheat sheet also covers grouping, chaining operations, subsetting with logical operators, and advanced utilities like type conversion, reordering, deleting, renaming, and setting keys for efficient lookups and joins.",{"@graph":63,"@context":118},[64,80,101],{"@type":65,"itemListElement":66},"BreadcrumbList",[67,71,74,77],{"item":68,"name":69,"@type":70,"position":9},"https://docshare.wps.com","Home","ListItem",{"item":72,"name":10,"@type":70,"position":73},"https://docshare.wps.com/template/",2,{"item":75,"name":11,"@type":70,"position":76},"https://docshare.wps.com/template/presentations/",3,{"item":78,"name":59,"@type":70,"position":79},"https://docshare.wps.com/template/data-transformation-with-datatable-cheat-sheet/572989/",4,{"url":78,"name":59,"@type":81,"image":82,"author":87,"headline":59,"publisher":90,"fileFormat":93,"inLanguage":57,"description":61,"dateModified":94,"datePublished":95,"encodingFormat":93,"isAccessibleForFree":96,"interactionStatistic":97},"DigitalDocument",{"url":83,"@type":84,"width":85,"height":86},"https://docshare.wps.com/thumbnails/data-transformation-with-datatable-cheat-sheet/572989.png","ImageObject",442,249,{"name":88,"@type":89},"Rainbow Cat","Person",{"url":68,"name":91,"@type":92},"DocShare","Organization","application/pdf","2026-10-19","2026-10-13",true,{"@type":98,"interactionType":99,"userInteractionCount":76},"InteractionCounter",{"@type":100},"ViewAction",{"@type":102,"mainEntity":103},"FAQPage",[104,110,114],{"name":105,"@type":106,"acceptedAnswer":107},"What does dt[i, j, by] mean in data.table?","Question",{"text":108,"@type":109},"dt[i, j, by] specifies row selection with i, column operations with j, and grouping behavior using by. data.tables keep the same data.frame-like function compatibility while adding these enhanced capabilities.","Answer",{"name":111,"@type":106,"acceptedAnswer":112},"How do you extract and summarize data in data.table?",{"text":113,"@type":109},"You can extract columns using dt[, c(2)] (by index) or dt[, .(b, c)] (by name). Summarize rows with expressions like dt[, .(x = sum(a))] and group using by, applying summary functions such as mean, median, min, and max.",{"name":115,"@type":106,"acceptedAnswer":116},"How do joins work between two data.tables?",{"text":117,"@type":109},"Joins use syntax like dt_a[dt_b, on = .(b = y)] to match rows based on specified equality conditions. Rolling joins with roll=TRUE keep only the most recent preceding match, and complex conditions can include both equal and unequal comparisons in on.","https://schema.org",{"og:url":78,"og:type":120,"og:title":59,"og:site_name":91,"og:description":61},"article",{"robots":122,"canonical":78},"index,follow",{"doc_id":124,"site_id":56},572989,1792338199,{"code":4,"msg":5,"data":127},{"doc_id":124,"user_id":128,"nickname":88,"user_avatar":129,"doc_module":9,"category_id":8,"category_name":11,"doc_title":59,"doc_description":61,"doc_content":130,"file_id":131,"file_url":132,"file_type":133,"file_size":134,"view_count":76,"is_deleted":4,"is_public":9,"is_downloadable":9,"audit_status":9,"page_count":73,"language":135,"language_code":57,"site_id":56,"html_lang":57,"table_of_contents":136,"faqs":137,"seo_title":138,"seo_description":61,"update_tm":139,"read_time":9},962090769181,"https://ap-avatar.wpscdn.com/davatar_6f874abed73319feea01a86fa6f0fab8","Data Transformation with data.table : : CHEAT SHEET  \nBasics  \ndata.table is an extremely fast and memory efficient package for transforming data in R with a concise syntax. It works by converting R’s native data frame objects into data.tables with new and enhanced functionality. The basics of working with data.tables are:  \ndt [i , j , by]  \nTake data.table dt, subset rows using i and manipulate columns with j, grouped according to by.  \ndata.tables are also data frames – functions that work with data frames also work with data.tables.  \nCreate a data.table  \ndata.table( a = c(1, 2), b = c(\"a\", \"b\")) create a data.table from scratch. Analogous to data.frame() .  \nsetDT(df)* [or](or as.data.table)[ as.data.table](or as.data.table)(df)  \nconvert a data frame or a list to a data.table.  \nManipulate columns with j  \nEXTRACT  \ndt[, c(2)]  \nextract columns by number. Prefix column numbers with “-” to drop.  \ndt[, .(b, c)]  \nextract columns by name.  \nSUMMARIZE  \ndt[, .(x = sum(a))]  \ncreate a data.table with new columns based on the summarized values of rows.  \nSummary functions like mean(), median(), min(), max(), etc. can be used to summarize rows.  \nCOMPUTE COLUMNS*  \n|  |  | c |\n| --- | --- | --- |\n|  |  | 3 |\n|  |  | 3 |\n\ndt[, c := 1 + 2]  \ncompute a column based on an expression.  \nGroup according to by  \n\n| a |  |  |\n| --- | --- | --- |\n|  |  |  |\n|  |  |  |\n|  |  |  |\n|  |  |  |\n|  |  |  |\n|  |  |  |\n\ndt[, j , by = .(a)] group rows by values in specified columns.  \ndt[, j , keyby = .(a)] group and simultaneously sort rows by values in specified columns.  \nCOMMON GROUPED OPERATIONS  \ndt[, .(c = sum(b)) , by = a] – summarize rows within groups.  \ndt[, c := sum(b) , by = a] – create a new column and compute rows within groups.  \ndt[, .SD[1], by = a] – extract first row of groups.  \ndt[, .SD[.N], by = a] – extract last row of groups.  \nChaining  \ndt[…][…]  \nperform a sequence of data.table operations by chaining multiple“[]”.  \nSubset rows using i  \n\n| a |  |\n| --- | --- |\n| 2 |  |\n| 1 |  |\n\ndt[a == 1 , c := 1 + 2]  \ncompute a column based on an expression but only for a subset of rows.  \nFunctions for data.tables  \ndt[1:2]  \nsubset rows based on row numbers.  \ndt[a > 5]  \nsubset rows based on values in one or more columns.  \nLOGICAL OPERATORS TO USE IN i  \n\u003C>  \n\u003C=  \n>=  \n[is.na](is.na) ()! [is.na](is.na) ()  \n%in%  \n!  \n|&  \n%like%%between%  \n|  |  | c | d |\n| --- | --- | --- | --- |\n|  |  | 1 | 2 |\n|  |  | 1 | 2 |\n\ndt[, ` := `(c = 1 , d = 2)] compute multiple columns based on separate expressions.  \nDELETE COLUMN  \n\n|  |  | c |  |  |  |\n| --- | --- | --- | --- | --- | --- |\n|  |  |  |  |  |  |\n|  |  |  |  |  |  |\n\ndt[, c := NULL] delete a column.  \nCONVERT COLUMN TYPE  \n\n|  | b |  |\n| --- | --- | --- |\n|  | 1.5 |  |\n|  | 2.6 |  |\n\n\n|  | b |\n| --- | --- |\n|  | 1 |\n|  | 2 |\n\ndt[, b := as.integer(b)]  \nconvert the type of a column using as.integer(), as. numeric(), as.character(), as. Date(), etc..  \nREORDER  \nsetorder(dt, a, -b)  \nreorder a data.table according to specified columns. Prefix column names with “-” for descending order.  \n* SET FUNCTIONS AND :=  \ndata.table’s functions prefixed with “set” and the operator “:=”work without “\u003C -” to alter data without making copies in memory. E.g., the more efficient “setDT(df)” is analogous to“df \u003C-[as.data.table](as.data.table) (df)”.  \nCreated by Erik Petrovsky and Mara Destefanis – [maragdestefanis@gmail.com](maragdestefanis@gmail.com) • Edited by Tyson Barrett • Learn more with the data.table  homepage or vignette • data.table version 1.17.8 • Updated: 2026-07  \nUNIQUE ROWS  \n\n| a | b |  |  |\n| --- | --- | --- | --- |\n| 1 | 2 |  |  |\n| 2 | 2 |  |  |\n| 1 | 2 |  |  |\n\nunique(dt, by = c(\"a\", \"b\")) extract unique rows based on columns specified in “by”. Leave out “by” to use all columns.  \nuniqueN(dt, by = c(\"a\", \"b\"))  \ncount the number of unique rows based on columns specified in“by”.  \nRENAME COLUMNS  \nsetnames(dt, c(\"a\", \" b \" ), c( \"x \" ,\"y\"))  \nrename columns from old names (a","cbCainZoJm0TxJga","https://ap.wps.com/l/cbCainZoJm0TxJga","pdf",189723,"English","# Basics\n## Creating and converting data.tables\n## dt[i, j, by]\n# Column operations\n## Extract, summarize, and compute\n## Subsetting with i\n# Grouped operations\n## Grouping with by / keyby\n## Common grouped operations\n# Chaining and grouped data\n## Chaining dt[…][…]\n# Utility functions\n## DELETE, convert type, REORDER\n## UNIQUE rows, rename columns, SET KEYS\n# Combine and reshape\n## JOIN\n## Rolling join\n## BIND (rbind, cbind)","[{\"question\":\"What does dt[i, j, by] mean in data.table?\",\"answer\":\"dt[i, j, by] specifies row selection with i, column operations with j, and grouping behavior using by. data.tables keep the same data.frame-like function compatibility while adding these enhanced capabilities.\"},{\"question\":\"How do you extract and summarize data in data.table?\",\"answer\":\"You can extract columns using dt[, c(2)] (by index) or dt[, .(b, c)] (by name). Summarize rows with expressions like dt[, .(x = sum(a))] and group using by, applying summary functions such as mean, median, min, and max.\"},{\"question\":\"How do joins work between two data.tables?\",\"answer\":\"Joins use syntax like dt_a[dt_b, on = .(b = y)] to match rows based on specified equality conditions. Rolling joins with roll=TRUE keep only the most recent preceding match, and complex conditions can include both equal and unequal comparisons in on.\"}]","Data Transformation with data.table - Cheat Sheet | PDF",1791930397]