R !!!時間の処理 *文字列ではなくDateという日付クラスのデータとして扱うようにする。<> Dは大文字 *<>で、何日差があるか出る **「差がある」というのは「何日ずれているか」ということで、今日と明日とでは1日差があると数える {{pre > as.Date("2019-10-25") [1] "2019-10-25" > class(as.Date("2019-10-25")) [1] "Date" > day1 <- as.Date("2019-10-25") > day2 <- as.Date("2020-10-25") > difftime(day1, day2) Time difference of -366 days > difftime(day2, day1) Time difference of 366 days }} !difftime() のオプション *units="単位" で数える単位を指定できる secs mins hours days weeks {{pre > difftime(day2, day1) Time difference of 366 days > difftime(day2, day1, units="weeks") Time difference of 52.28571 weeks > difftime(day2, day1, units="hours") Time difference of 8784 hours > difftime(day2, day1, units="mins") Time difference of 527040 mins > difftime(day2, day1, units="secs") Time difference of 31622400 secs }}