[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-573759-105":3,"detail-sidebar-cat-1-en-105":80,"doc-detail-573759-en":126},{"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":73,"head_meta":75,"extra_data":77,"updated_unix":79},105,"en","day-3-cheatsheet-subsetting-data-in-r","Day-3 Cheatsheet - Subsetting Data in R","","Day 3 Cheatsheet provides a compact reference for subsetting and inspecting tabular data in R. It lists key libraries and functions from Base R and dplyr, including selecting columns, filtering rows by logical conditions, viewing structure with glimpse, and working with dimensions such as nrow and ncol. The sheet also covers operators and tidyverse piping (%>%), plus helpers like starts_with and ends_with, along with row/column name transformations and renaming utilities.",{"@graph":14,"@context":72},[15,34,55],{"@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/template/","Template",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/template/presentations/","Presentations",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/template/day-3-cheatsheet-subsetting-data-in-r/573759/",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/day-3-cheatsheet-subsetting-data-in-r/573759.png","ImageObject",442,249,{"name":42,"@type":43},"Malam Tenang","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-10-16","2026-10-14",true,{"@type":52,"interactionType":53,"userInteractionCount":26},"InteractionCounter",{"@type":54},"ViewAction",{"@type":56,"mainEntity":57},"FAQPage",[58,64,68],{"name":59,"@type":60,"acceptedAnswer":61},"Which Base R functions help with row/column counts and structure overview?","Question",{"text":62,"@type":63},"Use nrow(x) and ncol(x) for counts, dim(x) for dimensions, and glimpse(x) for an overview of a data frame.","Answer",{"name":65,"@type":60,"acceptedAnswer":66},"How do you filter rows in dplyr based on conditions?",{"text":67,"@type":63},"Use filter(df, \u003Clogical condition>) such as filter(df, mpg > 20) to keep rows matching the condition.",{"name":69,"@type":60,"acceptedAnswer":70},"What does the %in% operator do in subsetting?",{"text":71,"@type":63},"%in% checks whether values on the left side are present in a vector or R object on the right side, returning TRUE or FALSE for use with filter().","https://schema.org",{"og:url":32,"og:type":74,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":76,"canonical":32},"index,follow",{"doc_id":78,"site_id":7},573759,1792127962,{"code":4,"msg":81,"data":82},"success",[83,87,92,97,102,107,112,117,122],{"id":84,"doc_module":22,"doc_module_name":25,"category_name":29,"show_sort_weight":85,"slug":86},11,90,"presentations",{"id":88,"doc_module":22,"doc_module_name":25,"category_name":89,"show_sort_weight":90,"slug":91},12,"Resumes",80,"resumes",{"id":93,"doc_module":22,"doc_module_name":25,"category_name":94,"show_sort_weight":95,"slug":96},14,"Invoices",70,"invoices",{"id":98,"doc_module":22,"doc_module_name":25,"category_name":99,"show_sort_weight":100,"slug":101},15,"Posters",60,"posters",{"id":103,"doc_module":22,"doc_module_name":25,"category_name":104,"show_sort_weight":105,"slug":106},16,"Social Media",50,"social-media",{"id":108,"doc_module":22,"doc_module_name":25,"category_name":109,"show_sort_weight":110,"slug":111},17,"Forms",40,"forms",{"id":113,"doc_module":22,"doc_module_name":25,"category_name":114,"show_sort_weight":115,"slug":116},18,"Letters",30,"letters",{"id":118,"doc_module":22,"doc_module_name":25,"category_name":119,"show_sort_weight":120,"slug":121},21,"Paper Templates",5,"papers-templates",{"id":123,"doc_module":22,"doc_module_name":25,"category_name":124,"show_sort_weight":4,"slug":125},158,"General","general-158",{"code":4,"msg":81,"data":127},{"doc_id":78,"user_id":128,"nickname":42,"user_avatar":129,"doc_module":22,"category_id":84,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":130,"file_id":131,"file_url":132,"file_type":133,"file_size":134,"view_count":26,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":26,"language":135,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":136,"faqs":137,"seo_title":138,"seo_description":12,"update_tm":139,"read_time":22},962093532863,"https://ap-avatar.wpscdn.com/davatar_276721f389ce27ea32af1340a28f341c","Day 3 Cheatsheet Subsetting Data in R  \nFunctions  \nLibrary/Package  \nPiece of code  \nExample of usage  \nWhat it does  \nBase R  \nBase R  \ndplyr  \ndplyr  \nBase R  \nBase R  \ntibble  \ntibble  \ndplyr  \ndplyr  \ndplyr  \ndplyr  \nnrow(x) ; ncol(x)  \ndim(x)  \nglimpse(x)  \nslice_sample(x) data.frame()  \ntibble()  \ncolumn_to_rownames()  \nrownames_to_column()  \nrename()  \npull() select()  \nfilter()  \nnrow(x) ; ncol(x)  \ndim(x)  \nglimpse(mtcars)  \nslice_sample(mtcars)  \ndf \u003C -data .frame(1:3)  \ntibble(mtcars)  \ndf \u003C -df %>%  \ncolumn_to_rownames( ' old_col ' )  \ndf \u003C -df %>%  \ncolumn_to_rownames( ' new_col ' )  \ndf \u003C -rename(df, MPG = mpg)  \npull(df, ' old_col ' ) select(df, ' old_col ' )  \nfilter(df, mpg > 20)  \nGet the number of rows and the number of columns in an object x, respectively.  \nGet the number of rows and number of columns in an object x  \nGet an overview of data frame x See a random subset of the rows of x  \nCreates a data frame where the named arguments will be the same length.  \nCreates a tibble from a  \ndata.frame or matrix. Transforms an existing column called by a string into the rownames.  \nTransforms the rownames of a data frame into a column (which is added to the start of the data frame) . The string supplied asan argument will be the name of the new column.  \nRenames designated columns while keeping all variables of the data.frame  \nExtract a column as a vector Selects columns that match the specified argument  \nReturns a subset of rows matching the conditions of the specified logical argument  \n\n| Library/Package | Piece of code | Example of usage | What it does |\n| --- | --- | --- | --- |\n| Base R | ==, \u003C=, >=, != | filter(df, mpg > 20) | These are binary operators |\n| Base R | %in% | filter(df, mpg %in% c(20,21,22)) | which allow for the comparison of values in an object. They are handy for use with filter() Checks if the given value(s) on the left side of the operator are in the vector or other R object defined on the right side of the operator. It returns a logical TRUE or FALSE statement. |\n| dplyr | %>% | df \u003C -df %>%\u003Cbr>select( ' new_variable_name ' ) | Funnels a data.frame through tidyverse operations |\n| dplyr | mutate() | df \u003C -mutate(df, newcol = | Adds a new column that is a |\n| dplyr | relocate() | wt/2.2)\u003Cbr>df_carb \u003C -relocate(.data = df, wt, .before = mpg) | function of existing columns Reorder columns in a data frame or tibble |\n| dplyr | arrange() | df \u003C -arrange(df, mpg) | Reorders rows in ascending order. arrange(desc()) would reorder rows in descending order. |\n| dplyr | starts_with() ; ends_with() | df \u003C -select(df,\u003Cbr>starts_with(\"B\"), year) | This function allows you to select columns based on a |\n| Base R | colnames() | colnames(df) | particular column name pattern. Gets or sets the column names of a matrix or data frame. |\n\n• See tidyselect helpers for handy things to use with select() .  \n* This format was adapted from the cheatsheet format from AlexsLemonade.","cbCaiv6FeMtTomDP","https://ap.wps.com/l/cbCaiv6FeMtTomDP","pdf",123281,"English","# Functions\n## Base R subsetting and inspection\n## dplyr tidyverse operations\n## Column name and row/column conversions","[{\"question\":\"Which Base R functions help with row/column counts and structure overview?\",\"answer\":\"Use nrow(x) and ncol(x) for counts, dim(x) for dimensions, and glimpse(x) for an overview of a data frame.\"},{\"question\":\"How do you filter rows in dplyr based on conditions?\",\"answer\":\"Use filter(df, \\u003clogical condition\\u003e) such as filter(df, mpg \\u003e 20) to keep rows matching the condition.\"},{\"question\":\"What does the %in% operator do in subsetting?\",\"answer\":\"%in% checks whether values on the left side are present in a vector or R object on the right side, returning TRUE or FALSE for use with filter().\"}]","Day-3 Cheatsheet - Subsetting Data in R | PDF",1791945048]