{"id":3931,"date":"2023-07-14T16:54:38","date_gmt":"2023-07-14T16:54:38","guid":{"rendered":"https:\/\/statorials.org\/it\/r-sottrarre-ore-dallora\/"},"modified":"2023-07-14T16:54:38","modified_gmt":"2023-07-14T16:54:38","slug":"r-sottrarre-ore-dallora","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/r-sottrarre-ore-dallora\/","title":{"rendered":"Come sottrarre ore dal tempo in r (con esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare uno dei seguenti metodi per sottrarre un determinato numero di ore da un&#8217;ora in R:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: utilizzare Base R<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create new column that subtracts 4 hours from time\n<\/span>df$subtract4 &lt;- df$time - ( <span style=\"color: #008000;\">4<\/span> * <span style=\"color: #008000;\">3600<\/span> )\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: utilizzare il pacchetto Lubrificante<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (lubridate)\n\n<span style=\"color: #008080;\">#create new column that subtracts 4 hours from time\n<\/span>df$subtract4 &lt;- df$time - hours( <span style=\"color: #008000;\">4<\/span> )\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Gli esempi seguenti mostrano come utilizzare ciascun metodo con il seguente frame di dati:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create data frame\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (time=as. <span style=\"color: #3366ff;\">POSIXct<\/span> (c('2022-01-03 08:04:15', '2022-01-05 14:04:15',\n                                   '2022-01-05 20:03:53', '2022-01-06 03:29:13',\n                                   '2022-01-06 06:15:00', '2022-01-07 10:48:11'),\n                                   format='%Y-%m-%d %H:%M:%OS'),\n                 sales=c(130, 98, 240, 244, 174, 193))\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n                 time sales\n1 2022-01-03 08:04:15 130\n2 2022-01-05 14:04:15 98\n3 2022-01-05 20:03:53 240\n4 2022-01-06 03:29:13 244\n5 2022-01-06 06:15:00 174\n6 2022-01-07 10:48:11 193\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : per aggiungere ore a una data, sostituisci semplicemente il segno di sottrazione con un segno di addizione in una delle formule sopra.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 1: sottrarre ore dal tempo utilizzando la base R<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come creare una nuova colonna denominata <b>sottrazione4<\/b> che sottrae quattro volte da ciascun valore nella colonna <strong>temporale<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#create new column that subtracts 4 hours from time<\/span>\ndf$subtract4 &lt;- df$time - ( <span style=\"color: #008000;\">4<\/span> * <span style=\"color: #008000;\">3600<\/span> )\n\n<span style=\"color: #008080;\">#view updated data frame\n<\/span>df\n\n                 time sales subtract4\n1 2022-01-03 08:04:15 130 2022-01-03 04:04:15\n2 2022-01-05 14:04:15 98 2022-01-05 10:04:15\n3 2022-01-05 20:03:53 240 2022-01-05 16:03:53\n4 2022-01-06 03:29:13 244 2022-01-05 23:29:13\n5 2022-01-06 06:15:00 174 2022-01-06 02:15:00\n6 2022-01-07 10:48:11 193 2022-01-07 06:48:11<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che i valori nella nuova colonna <b>sottrat4<\/b> sono uguali ai valori nella colonna <b>temporale<\/b> con quattro ore sottratte.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\"><strong>Nota<\/strong> : utilizziamo (4*3600) nella formula perch\u00e9 i valori temporali sono memorizzati come secondi in R. Poich\u00e9 in un&#8217;ora ci sono 3600 secondi, dobbiamo moltiplicare 4 per 3600 per sottrarre 4 ore.<\/span><\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio 2: sottrarre ore dal tempo utilizzando il pacchetto Lubrificate<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come utilizzare la funzione <strong>Hours()<\/strong> del pacchetto <a href=\"https:\/\/lubridate.tidyverse.org\/index.html\" target=\"_blank\" rel=\"noopener\">lubridate<\/a> per creare una nuova colonna chiamata <b>sottrat4<\/b> che sottrae quattro ore da ciascun valore nella colonna <strong>Time<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">library<\/span> (lubridate)<\/span>\n\n#create new column that subtracts 4 hours from time\n<\/span>df$subtract4 &lt;- df$time - hours( <span style=\"color: #008000;\">4<\/span> )\n\n<span style=\"color: #008080;\">#view updated data frame\n<\/span>df\n\n                 time sales subtract4\n1 2022-01-03 08:04:15 130 2022-01-03 04:04:15\n2 2022-01-05 14:04:15 98 2022-01-05 10:04:15\n3 2022-01-05 20:03:53 240 2022-01-05 16:03:53\n4 2022-01-06 03:29:13 244 2022-01-05 23:29:13\n5 2022-01-06 06:15:00 174 2022-01-06 02:15:00\n6 2022-01-07 10:48:11 193 2022-01-07 06:48:11<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che i valori nella nuova colonna <b>sottrat4<\/b> sono uguali ai valori nella colonna <b>temporale<\/b> con quattro ore sottratte.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">Si noti che questo metodo produce gli stessi risultati del metodo base R.<\/span><\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">I seguenti tutorial spiegano come eseguire altre attivit\u00e0 comuni in R:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/r-convertire-la-data-in-numerico\/\" target=\"_blank\" rel=\"noopener\">Come convertire una data in numerica in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/estrarre-il-mese-dalla-data-in-r\/\" target=\"_blank\" rel=\"noopener\">Come estrarre il mese dalla data in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/aggiungi-sottrai-il-mese-dalla-data-r\/\" target=\"_blank\" rel=\"noopener\">Come aggiungere e sottrarre mesi a una data in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare uno dei seguenti metodi per sottrarre un determinato numero di ore da un&#8217;ora in R: Metodo 1: utilizzare Base R #create new column that subtracts 4 hours from time df$subtract4 &lt;- df$time &#8211; ( 4 * 3600 ) Metodo 2: utilizzare il pacchetto Lubrificante library (lubridate) #create new column that subtracts 4 [&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 sottrarre ore al tempo in R (con esempi) \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come sottrarre ore dal tempo 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\/r-sottrarre-ore-dallora\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come sottrarre ore al tempo in R (con esempi) \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come sottrarre ore dal tempo in R, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/r-sottrarre-ore-dallora\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-14T16:54:38+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\/r-sottrarre-ore-dallora\/\",\"url\":\"https:\/\/statorials.org\/it\/r-sottrarre-ore-dallora\/\",\"name\":\"Come sottrarre ore al tempo in R (con esempi) \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-14T16:54:38+00:00\",\"dateModified\":\"2023-07-14T16:54:38+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come sottrarre ore dal tempo in R, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/r-sottrarre-ore-dallora\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/r-sottrarre-ore-dallora\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/r-sottrarre-ore-dallora\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come sottrarre ore dal tempo 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 sottrarre ore al tempo in R (con esempi) \u2013 Statorials","description":"Questo tutorial spiega come sottrarre ore dal tempo 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\/r-sottrarre-ore-dallora\/","og_locale":"it_IT","og_type":"article","og_title":"Come sottrarre ore al tempo in R (con esempi) \u2013 Statorials","og_description":"Questo tutorial spiega come sottrarre ore dal tempo in R, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/r-sottrarre-ore-dallora\/","og_site_name":"Statorials","article_published_time":"2023-07-14T16:54:38+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\/r-sottrarre-ore-dallora\/","url":"https:\/\/statorials.org\/it\/r-sottrarre-ore-dallora\/","name":"Come sottrarre ore al tempo in R (con esempi) \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-14T16:54:38+00:00","dateModified":"2023-07-14T16:54:38+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come sottrarre ore dal tempo in R, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/r-sottrarre-ore-dallora\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/r-sottrarre-ore-dallora\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/r-sottrarre-ore-dallora\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come sottrarre ore dal tempo 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\/3931"}],"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=3931"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3931\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}