{"id":3083,"date":"2015-07-08T14:34:39","date_gmt":"2015-07-08T13:34:39","guid":{"rendered":"https:\/\/abcdr.guyader.pro\/?p=3083"},"modified":"2018-04-08T00:01:43","modified_gmt":"2018-04-07T23:01:43","slug":"comment-passer-dun-format-wide-a-un-format-long-pour-un-data-frame-reshape","status":"publish","type":"post","link":"https:\/\/thinkr.fr\/abcdr\/comment-passer-dun-format-wide-a-un-format-long-pour-un-data-frame-reshape\/","title":{"rendered":"Comment passer d&#039;un format Wide \u00e0 un format Long pour un data.frame ? : reshape"},"content":{"rendered":"<p>La fonction <b>reshape() <\/b>permet de modifier le format des donn\u00e9es en fonction de la variable qu\u2019on associe au param\u00e8tre \u00ab\u00a0direction\u00a0\u00bb.<\/p>\n<pre><code>\n\ndf &lt;- data.frame(id = rep(1:4, rep(2,4)),\n\n\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0visit = I(rep(c(\"Before\",\"After\"), 4)),\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 x = rnorm(4), y = runif(4))\n\ndf # df est un data.frame de dimension 8 X 4 avec des r\u00e9p\u00e9titions<br \/>\u00a0\n\n# On simplifie le tableau en enlevant les r\u00e9p\u00e9titions\n\ndf2=reshape(df, timevar = \"visit\", idvar = \"id\", direction = \"wide\")<br \/>\u00a0\n\n# Le param\u00e8tre \u00ab direction \u00bb associ\u00e9 \u00e0 la valeur \u00ab long \u00bb permet de r\u00e9cup\u00e9rer le format original des donn\u00e9es.\n\nreshape(df2, timevar = \"visit\", idvar = \"id\", direction = \"long\")<br \/> <\/code><\/pre>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>La fonction reshape() permet de modifier le format des donn\u00e9es en fonction de la variable qu\u2019on associe au param\u00e8tre \u00ab\u00a0direction\u00a0\u00bb. df &lt;- data.frame(id = rep(1:4, rep(2,4)), \u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0visit = I(rep(c(\u00ab\u00a0Before\u00a0\u00bb,\u00a0\u00bbAfter\u00a0\u00bb), 4)), \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 x = rnorm(4), y = runif(4)) df # df est un data.frame de dimension 8 X 4 avec des r\u00e9p\u00e9titions\u00a0 # On simplifie le tableau en enlevant les r\u00e9p\u00e9titions df2=reshape(df, timevar = \u00ab\u00a0visit\u00a0\u00bb, idvar = \u00ab\u00a0id\u00a0\u00bb, direction = \u00ab\u00a0wide\u00a0\u00bb)\u00a0 # Le param\u00e8tre \u00ab direction \u00bb associ\u00e9 \u00e0 la valeur \u00ab long \u00bb permet de r\u00e9cup\u00e9rer le format original des donn\u00e9es. reshape(df2, timevar = \u00ab\u00a0visit\u00a0\u00bb, idvar = \u00ab\u00a0id\u00a0\u00bb, direction = \u00ab\u00a0long\u00a0\u00bb) \u00a0<a class=\"more-link\" href=\"https:\/\/thinkr.fr\/abcdr\/comment-passer-dun-format-wide-a-un-format-long-pour-un-data-frame-reshape\/\">Read More &rarr;<\/a><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","rop_custom_images_group":[],"rop_custom_messages_group":[],"rop_publish_now":"initial","rop_publish_now_accounts":{"twitter_399453572_399453572":""},"rop_publish_now_history":[],"rop_publish_now_status":"pending","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[12,23],"tags":[],"class_list":{"0":"entry","1":"post","2":"publish","3":"author-helene","4":"post-3083","6":"format-standard","7":"category-manipulation-de-donnees","8":"category-transformation-de-donnees"},"acf":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p9O7Sx-NJ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/posts\/3083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/comments?post=3083"}],"version-history":[{"count":2,"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/posts\/3083\/revisions"}],"predecessor-version":[{"id":4263,"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/posts\/3083\/revisions\/4263"}],"wp:attachment":[{"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/media?parent=3083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/categories?post=3083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thinkr.fr\/abcdr\/wp-json\/wp\/v2\/tags?post=3083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}