{"id":1133,"date":"2023-07-27T13:32:32","date_gmt":"2023-07-27T13:32:32","guid":{"rendered":"https:\/\/statorials.org\/it\/creare-la-tabella-in-r\/"},"modified":"2023-07-27T13:32:32","modified_gmt":"2023-07-27T13:32:32","slug":"creare-la-tabella-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/creare-la-tabella-in-r\/","title":{"rendered":"Come creare tabelle in r (con esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Esistono due modi per creare rapidamente tabelle in R:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: creare una tabella dai dati esistenti.<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>tab &lt;- <span style=\"color: #3366ff;\">table<\/span> (df$row_variable, df$column_variable)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: crea una tabella da zero.<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>tab &lt;- <span style=\"color: #3366ff;\">matrix<\/span> (c(7, 5, 14, 19, 3, 2, 17, 6, 12), ncol= <span style=\"color: #993300;\">3<\/span> , byrow= <span style=\"color: #008000;\">TRUE<\/span> )\ncolnames(tab) &lt;- c('colName1','colName2','colName3')\nrownames(tab) &lt;- c('rowName1','rowName2','rowName3')\ntab &lt;- <span style=\"color: #3366ff;\">as.table<\/span> (tab)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo tutorial mostra un esempio di creazione di una tabella utilizzando ciascuno di questi metodi.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Crea una tabella dai dati esistenti<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come creare una tabella da dati esistenti:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#make this example reproducible<\/span>\nset.seed(1)\n\n<span style=\"color: #008080;\">#define data\n<span style=\"color: #000000;\">df &lt;- data.frame(team= <span style=\"color: #3366ff;\">rep<\/span> (c(' <span style=\"color: #008000;\">A<\/span> ', ' <span style=\"color: #008000;\">B<\/span> ', ' <span style=\"color: #008000;\">C<\/span> ', ' <span style=\"color: #008000;\">D<\/span> '), each= <span style=\"color: #993300;\">4<\/span> ),\n                 pos= <span style=\"color: #3366ff;\">rep<\/span> (c(' <span style=\"color: #008000;\">G<\/span> ', ' <span style=\"color: #008000;\">F<\/span> '), times= <span style=\"color: #993300;\">8<\/span> ),\n                 points= <span style=\"color: #3366ff;\">round<\/span> (runif(16, 4, 20), <span style=\"color: #993300;\">0<\/span> ))\n\n<span style=\"color: #008080;\">#view head of data \n<\/span>head(df)\n\n  team pos points\n1 GA 8\n2 AF10\n3 AG 13\n4 FY19\n5 BG 7\n6 BF 18\n\n<span style=\"color: #008080;\">#create table with 'position' as rows and 'team' as columns<\/span>\ntab1 &lt;- table(df$pos, df$team)\ntab1\n\n  ABCD\nF 2 2 2 2\nG 2 2 2 2<\/span><\/span>\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questa tabella mostra le frequenze per ciascuna combinazione di squadra e posizione. Per esempio:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">2 giocatori sono nella posizione &#8220;F&#8221; nella squadra &#8220;A&#8221;<\/span><\/li>\n<li> <span style=\"color: #000000;\">2 giocatori sono nella posizione &#8220;G&#8221; nella squadra &#8220;A&#8221;<\/span><\/li>\n<li> <span style=\"color: #000000;\">2 giocatori sono nella posizione &#8216;F&#8217; nella squadra &#8216;B&#8217;<\/span><\/li>\n<li> <span style=\"color: #000000;\">2 giocatori sono nella posizione &#8216;G&#8217; nella squadra &#8216;B&#8217;<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">E cos\u00ec via.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Crea una tabella da zero<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come creare da zero una tabella con 4 colonne e 2 righe:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create matrix with 4 columns<\/span>\ntab &lt;- matrix( <span style=\"color: #3366ff;\">rep<\/span> (2, times= <span style=\"color: #993300;\">8<\/span> ), ncol= <span style=\"color: #993300;\">4<\/span> , byrow= <span style=\"color: #008000;\">TRUE<\/span> )\n\n<span style=\"color: #008080;\">#define column names and row names of matrix\n<\/span>colnames(tab) &lt;- c(' <span style=\"color: #008000;\">A<\/span> ', ' <span style=\"color: #008000;\">B<\/span> ', ' <span style=\"color: #008000;\">C<\/span> ', ' <span style=\"color: #008000;\">D<\/span> ')\nrownames(tab) &lt;- c(' <span style=\"color: #008000;\">F<\/span> ', ' <span style=\"color: #008000;\">G<\/span> ')\n\n<span style=\"color: #008080;\">#convert matrix to table<\/span>\ntab &lt;- <span style=\"color: #3366ff;\">as.table<\/span> (tab)\n\n<span style=\"color: #008080;\">#view table<\/span> \ntab\n\n  ABCD\nF 2 2 2 2\nG 2 2 2 2<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che questa tabella \u00e8 esattamente la stessa creata nell&#8217;esempio precedente.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/it\/r-colonne-del-frame-di-dati-del-loop\/\" target=\"_blank\" rel=\"noopener noreferrer\">Come scorrere i nomi delle colonne in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/creare-un-dataframe-vuoto-in-r\/\" target=\"_blank\" rel=\"noopener noreferrer\">Come creare un frame di dati vuoto in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/r-aggiungi-al-dataframe\/\" target=\"_blank\" rel=\"noopener noreferrer\">Come aggiungere righe a un frame di dati in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Esistono due modi per creare rapidamente tabelle in R: Metodo 1: creare una tabella dai dati esistenti. tab &lt;- table (df$row_variable, df$column_variable) Metodo 2: crea una tabella da zero. tab &lt;- matrix (c(7, 5, 14, 19, 3, 2, 17, 6, 12), ncol= 3 , byrow= TRUE ) colnames(tab) &lt;- c(&#8216;colName1&#8242;,&#8217;colName2&#8242;,&#8217;colName3&#8217;) rownames(tab) &lt;- c(&#8216;rowName1&#8242;,&#8217;rowName2&#8242;,&#8217;rowName3&#8217;) tab &lt;- [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Come creare tabelle in R (con esempi) \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come creare rapidamente tabelle in R, con diversi esempi.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/it\/creare-la-tabella-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come creare tabelle in R (con esempi) \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come creare rapidamente tabelle in R, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/creare-la-tabella-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-27T13:32:32+00:00\" \/>\n<meta name=\"author\" content=\"Benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/creare-la-tabella-in-r\/\",\"url\":\"https:\/\/statorials.org\/it\/creare-la-tabella-in-r\/\",\"name\":\"Come creare tabelle in R (con esempi) \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-27T13:32:32+00:00\",\"dateModified\":\"2023-07-27T13:32:32+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come creare rapidamente tabelle in R, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/creare-la-tabella-in-r\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/creare-la-tabella-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/creare-la-tabella-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come creare tabelle in r (con esempi)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/it\/#website\",\"url\":\"https:\/\/statorials.org\/it\/\",\"name\":\"Statorials\",\"description\":\"La tua guida all&#039;alfabetizzazione statistica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/it\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\",\"name\":\"Benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin anderson\"},\"description\":\"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9\",\"sameAs\":[\"https:\/\/statorials.org\/it\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Come creare tabelle in R (con esempi) \u2013 Statorials","description":"Questo tutorial spiega come creare rapidamente tabelle in R, con diversi esempi.","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:\/\/statorials.org\/it\/creare-la-tabella-in-r\/","og_locale":"it_IT","og_type":"article","og_title":"Come creare tabelle in R (con esempi) \u2013 Statorials","og_description":"Questo tutorial spiega come creare rapidamente tabelle in R, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/creare-la-tabella-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-27T13:32:32+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"2 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/creare-la-tabella-in-r\/","url":"https:\/\/statorials.org\/it\/creare-la-tabella-in-r\/","name":"Come creare tabelle in R (con esempi) \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-27T13:32:32+00:00","dateModified":"2023-07-27T13:32:32+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come creare rapidamente tabelle in R, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/creare-la-tabella-in-r\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/creare-la-tabella-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/creare-la-tabella-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come creare tabelle in r (con esempi)"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/it\/#website","url":"https:\/\/statorials.org\/it\/","name":"Statorials","description":"La tua guida all&#039;alfabetizzazione statistica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/it\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae","name":"Benjamin anderson","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Benjamin anderson"},"description":"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9","sameAs":["https:\/\/statorials.org\/it"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/1133"}],"collection":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/comments?post=1133"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/1133\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=1133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=1133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=1133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}