{"id":63585,"date":"2020-10-21T11:27:15","date_gmt":"2020-10-21T15:27:15","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=63585"},"modified":"2022-11-21T09:46:29","modified_gmt":"2022-11-21T14:46:29","slug":"working-with-tidy-financial-data-in-tidyr","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/working-with-tidy-financial-data-in-tidyr\/","title":{"rendered":"Working with Tidy Financial Data in tidyr"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Holding data in a tidy format works wonders for one\u2019s productivity.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here we will explore the&nbsp;<code>tidyr<\/code>&nbsp;package, which is all about creating tidy data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In particular, let\u2019s develop an understanding of the&nbsp;<code>tidyr::pivot_longer<\/code>&nbsp;and&nbsp;<code>tidyr::pivot_wider<\/code>&nbsp;functions for switching between different formats of tidy data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What\u2019s tidy data?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Tidy data is data where:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Every column is variable.<\/li><li>Every row is an observation.<\/li><li>Every cell is a single value.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Why do we care?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">It turns out there are huge benefits to thinking about the \u201cshape\u201d of your data and the best way to structure and manipulate it for your problem.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Tidy data is a standard way of shaping data that facilitates analysis. In particular, tidy data works very well with the tidyverse tools. Which means less time spent transforming and cleaning data and more time spent solving problems. In short, structuring data to facilitate analysis is an enormous productivity hack.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thinking in these terms has had a MASSIVE impact on the effectiveness and speed of our research. We\u2019re going to cover this in some detail in the Armageddon bootcamp, along with some specific patterns for doing trading analysis.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wide vs Long Data<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s take a look at some long-format data. This code loads a long dataframe of daily returns for various indexes and prints the observations from the beginning of March 2020:<\/p>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\nif (!require(&#8220;pacman&#8221;)) install.packages(&#8220;pacman&#8221;)<br>\npacman::p_load(tidyverse, here, knitr, kableExtra)<br><br>\nload(here(&#8216;data&#8217;, &#8216;indexreturns.RData&#8217;))<br>\ndailyindex_df <- dailyindex_df %>%<br>\n  filter(date >= &#8216;2020-03-01&#8217;) <br><br>\ndailyindex_df %>%<br>\n  kable() %>%<br>\n  kable_styling(full_width = FALSE, position = &#8216;center&#8217;) %>%<br>\n  scroll_box(width = &#8216;800px&#8217;, height = &#8216;300px&#8217;)<br>\n<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Note: the below is a snapshot.<\/em> <em>Visit <a href=\"https:\/\/robotwealth.com\/working-with-tidy-financial-data-in-tidyr\/\">Robot Wealth<\/a> website to see the full set of long data.<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"751\" height=\"263\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2020\/10\/robot-wealth-tidy1.png\" alt=\"\" class=\"wp-image-63595 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/10\/robot-wealth-tidy1.png 751w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/10\/robot-wealth-tidy1-700x245.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/10\/robot-wealth-tidy1-300x105.png 300w\" data-sizes=\"(max-width: 751px) 100vw, 751px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 751px; aspect-ratio: 751\/263;\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Long data is presented with one or more columns containing a key and another containing all the values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, the key, or so-called \u201cunit of analysis: is date-ticker. That is, each value (in the returns column) is uniquely associated with a date-ticker joint key.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The joint key date-ticker would be the starting point of any analysis we\u2019d want to do on this data set.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is often easier to manage and process. However, if you\u2019re used to looking at spreadsheets, it can be harder to understand intuitively.&nbsp;<em>(I think that this difficulty evaporates fairly quickly once you start using the tools).<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">While structuring data as key-value pairs might seem odd if you\u2019re not used to it, it does actually facilitate your conceptual clarity of the problem at hand.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, in the example above, it is clear that the unique identifier of each return is the date-ticker joint key.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With that clarity, it becomes much simpler to imagine the steps in an analysis workflow. You get quite productive and effective at this with a little practice.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s compare this with the same data in wide format:<\/p>\n\n\n\n<p style=\"background-color:#fcfcdb;font-size:11px\" class=\"has-background\">\ndailyindex_df %&gt;%<br>\n  pivot_wider(names_from = ticker, values_from = returns) %&gt;%<br>\n  kable() %&gt;%<br>\n  kable_styling(position = &#8216;center&#8217;) %&gt;%<br>\n  scroll_box(width = &#8216;800px&#8217;, height = &#8216;300px&#8217;)\n<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Note: the below is a snapshot. Visit <a href=\"https:\/\/robotwealth.com\/working-with-tidy-financial-data-in-tidyr\/\">Robot Wealth<\/a> website to see the full set of wide data.<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"717\" height=\"275\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2020\/10\/robot-wealth-tidy2.png\" alt=\"\" class=\"wp-image-63603 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/10\/robot-wealth-tidy2.png 717w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/10\/robot-wealth-tidy2-700x268.png 700w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/10\/robot-wealth-tidy2-300x115.png 300w\" data-sizes=\"(max-width: 717px) 100vw, 717px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 717px; aspect-ratio: 717\/275;\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This might look more familiar. Here we have a row for each date and a column for the return corresponding to each index. The unique values in the ticker column are actual columns in this wide format.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Data in this format is probably more amenable human consumption.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">So which is better \u2013 wide or long format?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">It depends!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You\u2019ll find that storing your data in long format facilitates exploration and analysis, particularly if you use the&nbsp;<code>tidyverse<\/code>&nbsp;tools. We highly recommend that you do all your tidy analysis in long format unless you have a good reason not to.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Long format data is also easy to maintain \u2013 adding a new variable<em>&nbsp;(a new ticker, say)<\/em>&nbsp;is as simple as appending rows to the bottom of the existing data frame (and maybe sorting it by date, if you wanted to).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One use case that you see all the time is using ggplot to visualise a variable for more than one member of some organising category, for example, a time series plot of a bunch of different price curves where the organising category is ticker.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On the other hand, wide-format data might be a better choice if you intend for a human to consume the data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You will also find certain functions and algorithms that expect data in this format, for example&nbsp;<code>stats::cor<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Visit Robot Wealth website to read the full article and watch the instructional video: <a href=\"https:\/\/robotwealth.com\/working-with-tidy-financial-data-in-tidyr\/\">https:\/\/robotwealth.com\/working-with-tidy-financial-data-in-tidyr\/<\/a><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kris Longmore explains what tidy data looks like, why it&#8217;s a sensible approach and the difference between long and wide tidy data.<\/p>\n","protected":false},"author":271,"featured_media":63588,"comment_status":"closed","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[339,343,338,350,341,344,342],"tags":[806,487,6591,8596,8594,1045],"contributors-categories":[13676],"class_list":["post-63585","post","type-post","status-publish","format-standard","has-post-thumbnail","category-data-science","category-programing-languages","category-ibkr-quant-news","category-quant-asia-pacific","category-quant-development","category-quant-regions","category-r-development","tag-data-science","tag-r","tag-rstats","tag-tidy-financial-data","tag-tidyr","tag-tidyverse","contributors-categories-robot-wealth"],"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.8) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Working with Tidy Financial Data in tidyr | IBKR Quant<\/title>\n<meta name=\"description\" content=\"Kris Longmore explains what tidy data looks like, why it&#039;s a sensible approach and the difference between long and wide tidy data.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/63585\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Working with Tidy Financial Data in tidyr | IBKR Quant Blog\" \/>\n<meta property=\"og:description\" content=\"Kris Longmore explains what tidy data looks like, why it&#039;s a sensible approach and the difference between long and wide tidy data.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/working-with-tidy-financial-data-in-tidyr\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2020-10-21T15:27:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-21T14:46:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/10\/digital-cube-numbers.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"900\" \/>\n\t<meta property=\"og:image:height\" content=\"550\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Kris Longmore\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kris Longmore\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/working-with-tidy-financial-data-in-tidyr\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/working-with-tidy-financial-data-in-tidyr\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Kris Longmore\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/79c2a2775a70a4da1accf0068d731933\"\n\t            },\n\t            \"headline\": \"Working with Tidy Financial Data in tidyr\",\n\t            \"datePublished\": \"2020-10-21T15:27:15+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:46:29+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/working-with-tidy-financial-data-in-tidyr\\\/\"\n\t            },\n\t            \"wordCount\": 771,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/working-with-tidy-financial-data-in-tidyr\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/10\\\/digital-cube-numbers.jpg\",\n\t            \"keywords\": [\n\t                \"Data Science\",\n\t                \"R\",\n\t                \"rstats\",\n\t                \"tidy financial data\",\n\t                \"tidyr\",\n\t                \"tidyverse\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Quant\",\n\t                \"Quant Asia Pacific\",\n\t                \"Quant Development\",\n\t                \"Quant Regions\",\n\t                \"R Development\"\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/working-with-tidy-financial-data-in-tidyr\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/working-with-tidy-financial-data-in-tidyr\\\/\",\n\t            \"name\": \"Working with Tidy Financial Data in tidyr | IBKR Quant Blog\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/working-with-tidy-financial-data-in-tidyr\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/working-with-tidy-financial-data-in-tidyr\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/10\\\/digital-cube-numbers.jpg\",\n\t            \"datePublished\": \"2020-10-21T15:27:15+00:00\",\n\t            \"dateModified\": \"2022-11-21T14:46:29+00:00\",\n\t            \"description\": \"Kris Longmore explains what tidy data looks like, why it's a sensible approach and the difference between long and wide tidy data.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/working-with-tidy-financial-data-in-tidyr\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/working-with-tidy-financial-data-in-tidyr\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/10\\\/digital-cube-numbers.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2020\\\/10\\\/digital-cube-numbers.jpg\",\n\t            \"width\": 900,\n\t            \"height\": 550,\n\t            \"caption\": \"world\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/79c2a2775a70a4da1accf0068d731933\",\n\t            \"name\": \"Kris Longmore\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/krislongmore\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Working with Tidy Financial Data in tidyr | IBKR Quant","description":"Kris Longmore explains what tidy data looks like, why it's a sensible approach and the difference between long and wide tidy data.","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:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/63585\/","og_locale":"en_US","og_type":"article","og_title":"Working with Tidy Financial Data in tidyr | IBKR Quant Blog","og_description":"Kris Longmore explains what tidy data looks like, why it's a sensible approach and the difference between long and wide tidy data.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/working-with-tidy-financial-data-in-tidyr\/","og_site_name":"IBKR Campus US","article_published_time":"2020-10-21T15:27:15+00:00","article_modified_time":"2022-11-21T14:46:29+00:00","og_image":[{"width":900,"height":550,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/10\/digital-cube-numbers.jpg","type":"image\/jpeg"}],"author":"Kris Longmore","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kris Longmore","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/working-with-tidy-financial-data-in-tidyr\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/working-with-tidy-financial-data-in-tidyr\/"},"author":{"name":"Kris Longmore","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/79c2a2775a70a4da1accf0068d731933"},"headline":"Working with Tidy Financial Data in tidyr","datePublished":"2020-10-21T15:27:15+00:00","dateModified":"2022-11-21T14:46:29+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/working-with-tidy-financial-data-in-tidyr\/"},"wordCount":771,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/working-with-tidy-financial-data-in-tidyr\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/10\/digital-cube-numbers.jpg","keywords":["Data Science","R","rstats","tidy financial data","tidyr","tidyverse"],"articleSection":["Data Science","Programming Languages","Quant","Quant Asia Pacific","Quant Development","Quant Regions","R Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/working-with-tidy-financial-data-in-tidyr\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/working-with-tidy-financial-data-in-tidyr\/","name":"Working with Tidy Financial Data in tidyr | IBKR Quant Blog","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/working-with-tidy-financial-data-in-tidyr\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/working-with-tidy-financial-data-in-tidyr\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/10\/digital-cube-numbers.jpg","datePublished":"2020-10-21T15:27:15+00:00","dateModified":"2022-11-21T14:46:29+00:00","description":"Kris Longmore explains what tidy data looks like, why it's a sensible approach and the difference between long and wide tidy data.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/working-with-tidy-financial-data-in-tidyr\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/working-with-tidy-financial-data-in-tidyr\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/10\/digital-cube-numbers.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/10\/digital-cube-numbers.jpg","width":900,"height":550,"caption":"world"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/79c2a2775a70a4da1accf0068d731933","name":"Kris Longmore","url":"https:\/\/www.interactivebrokers.com\/campus\/author\/krislongmore\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2020\/10\/digital-cube-numbers.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/63585","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/271"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=63585"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/63585\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/63588"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=63585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=63585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=63585"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=63585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}