行內代碼只需要一個已經存在的變數。R 代碼塊回傳正確的值,但行內代碼回傳 0。
我的代碼:
---
title: "Test"
output: html_document
---
```{r include=FALSE, echo=FALSE, message=FALSE, warning=FALSE}
library(tidyverse)
library(lubridate)
first_date <- ymd("2019-01-28")
last_date <- ymd("2020-03-12")
last_date - first_date
my_interval <- interval(first_date, last_date)
number_of_days <- as.period(my_interval, unit = "day")
number_of_days
without lubridate, the time difference is `r last_date - first_date` days and with lubridate it's `r number_of_days` days
我的輸出:

uj5u.com熱心網友回復:
它可能被轉換為整數:
> number_of_days
[1] "409d 0H 0M 0S"
> as.integer(number_of_days)
[1] 0
試試這個:
without lubridate, the time difference is `r last_date - first_date` days and with lubridate it's `r as.character(number_of_days)` days
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/449400.html
