Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.
Running Code
When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:
1+1
[1] 2
# Create a datetime object from the character stringd <-as.Date("05/08/2020", format ="%m/%d/%Y")d
[1] "2020-05-08"
# Check the data type of the datetime objecttypeof(d)
[1] "double"
# Install lubridate package if necessaryif (!require(lubridate)) {install.packages("lubridate")}
Loading required package: lubridate
Attaching package: 'lubridate'
The following objects are masked from 'package:base':
date, intersect, setdiff, union
# Load the lubridate packagelibrary(lubridate)# Extract year, month number, week number, and weekday numberd_year <-year(d)d_month <-month(d)d_week <-week(d)d_day <-wday(d)# Display the extracted valuesd_year
[1] 2020
d_month
[1] 5
d_week
[1] 19
d_day
[1] 6
# Create a datetime object for 25 days from the original dated_25 <- d +days(25)d_25
[1] "2020-06-02"
# Calculate the difference between d and d_25diff <-difftime(d_25, d, units ="days")# Display the differencediff
Time difference of 25 days
You can add options to executable code like this
[1] 4
The echo: false option disables the printing of code (only output is displayed).