{"id":30,"date":"2026-03-03T06:45:01","date_gmt":"2026-03-03T06:45:01","guid":{"rendered":"https:\/\/gigz.pk\/r\/?post_type=lesson&#038;p=30"},"modified":"2026-04-01T10:45:32","modified_gmt":"2026-04-01T10:45:32","slug":"data-frames-and-tibbles","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/r\/lesson\/data-frames-and-tibbles\/","title":{"rendered":"Data Frames and Tibbles"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Data frames and tibbles are two of the most important data structures in R for handling tabular data. They allow you to store and manipulate datasets consisting of multiple variables (columns) and observations (rows). Understanding them is crucial for data analysis and manipulation.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>1. Data Frames in R<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">A data frame is a two-dimensional structure where each column can contain different data types (numeric, character, logical, etc.). It is similar to a spreadsheet or SQL table.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Creating a Data Frame<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can create a data frame using the <code>data.frame()<\/code> function:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">my_data &lt;- data.frame(<br>  Name = c(\"Alice\", \"Bob\", \"Charlie\"),<br>  Age = c(25, 30, 28),<br>  Passed = c(TRUE, TRUE, FALSE)<br>)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Accessing Data Frame Elements<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can access columns using <code>$<\/code> or square brackets <code>[]<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">my_data$Name         # Returns the Name column<br>my_data[1, ]         # Returns the first row<br>my_data[ , \"Age\"]    # Returns the Age column<br>my_data[2,3]         # Returns the value in second row, third column<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Modifying Data Frames<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can add new columns or update existing ones:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">my_data$City &lt;- c(\"New York\", \"Los Angeles\", \"Chicago\")  # Add new column<br>my_data$Age[1] &lt;- 26                                     # Update value<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Common Data Frame Functions<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">str(my_data)     # Structure of the data frame<br>summary(my_data) # Summary statistics<br>nrow(my_data)    # Number of rows<br>ncol(my_data)    # Number of columns<br>head(my_data)    # First 6 rows<br>tail(my_data)    # Last 6 rows<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>2. Tibbles in R<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Tibbles are a modern version of data frames provided by the <strong>tidyverse<\/strong> package. They are designed to make data analysis easier by providing better printing, subsetting, and handling of large datasets.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Creating a Tibble<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">library(tibble)my_tibble &lt;- tibble(<br>  Name = c(\"Alice\", \"Bob\", \"Charlie\"),<br>  Age = c(25, 30, 28),<br>  Passed = c(TRUE, TRUE, FALSE)<br>)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Differences Between Data Frames and Tibbles<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Tibbles never convert strings to factors by default, while data frames do.<\/li>\n\n\n\n<li>Tibbles have a cleaner printing method that shows only the first 10 rows and columns that fit on the screen.<\/li>\n\n\n\n<li>Subsetting a single column in a tibble always returns a tibble, while in data frames it may return a vector.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Accessing Tibble Elements<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">my_tibble$Name         # Returns Name column<br>my_tibble[1, ]         # First row<br>my_tibble[ , \"Age\"]    # Age column<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Data frames and tibbles are essential for working with tabular data in R. Data frames are the standard structure for datasets, while tibbles provide a modern and user-friendly alternative with enhanced printing and handling. Mastering both will allow you to efficiently manage, manipulate, and analyze datasets in R.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/r\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">R Programming (R Lang) > Data Types and Structures > Data Frames and Tibbles<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1775040302655\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":7,"template":"","class_list":["post-30","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Data Frames and Tibbles - Analyze Deep. Visualize Better. Build with R.<\/title>\n<meta name=\"description\" content=\"Learn data frames and tibbles in R with differences and examples. Master creating, accessing, and modifying tabular data for analysis.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Data Frames and Tibbles - Analyze Deep. Visualize Better. Build with R.\" \/>\n<meta property=\"og:description\" content=\"Learn data frames and tibbles in R with differences and examples. Master creating, accessing, and modifying tabular data for analysis.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:site_name\" content=\"Analyze Deep. Visualize Better. Build with R.\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-01T10:45:32+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/r\\\/lesson\\\/data-frames-and-tibbles\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/\",\"name\":\"Data Frames and Tibbles - Analyze Deep. Visualize Better. Build with R.\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/r\\\/#website\"},\"datePublished\":\"2026-03-03T06:45:01+00:00\",\"dateModified\":\"2026-04-01T10:45:32+00:00\",\"description\":\"Learn data frames and tibbles in R with differences and examples. Master creating, accessing, and modifying tabular data for analysis.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/r\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"R Programming (R Lang) > Data Types and Structures > Data Frames and Tibbles\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/r\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/r\\\/\",\"name\":\"Analyze Deep. Visualize Better. Build with R.\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/r\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Data Frames and Tibbles - Analyze Deep. Visualize Better. Build with R.","description":"Learn data frames and tibbles in R with differences and examples. Master creating, accessing, and modifying tabular data for analysis.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/","og_locale":"en_US","og_type":"article","og_title":"Data Frames and Tibbles - Analyze Deep. Visualize Better. Build with R.","og_description":"Learn data frames and tibbles in R with differences and examples. Master creating, accessing, and modifying tabular data for analysis.","og_url":"https:\/\/gigz.pk\/","og_site_name":"Analyze Deep. Visualize Better. Build with R.","article_modified_time":"2026-04-01T10:45:32+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/r\/lesson\/data-frames-and-tibbles\/","url":"https:\/\/gigz.pk\/","name":"Data Frames and Tibbles - Analyze Deep. Visualize Better. Build with R.","isPartOf":{"@id":"https:\/\/gigz.pk\/r\/#website"},"datePublished":"2026-03-03T06:45:01+00:00","dateModified":"2026-04-01T10:45:32+00:00","description":"Learn data frames and tibbles in R with differences and examples. Master creating, accessing, and modifying tabular data for analysis.","breadcrumb":{"@id":"https:\/\/gigz.pk\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/r\/"},{"@type":"ListItem","position":2,"name":"R Programming (R Lang) > Data Types and Structures > Data Frames and Tibbles"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/r\/#website","url":"https:\/\/gigz.pk\/r\/","name":"Analyze Deep. Visualize Better. Build with R.","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/r\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/r\/wp-json\/wp\/v2\/lesson\/30","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/r\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/r\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/r\/wp-json\/wp\/v2\/media?parent=30"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}