numbers <- c(12, 18, 20, 25, 30)
mean(numbers)[1] 21
sum(numbers)[1] 105
R Basics and Data Visualization
This is my first Quarto test document. It demonstrates Markdown formatting, R calculations, a data table, and a chart. The data below are illustrative examples, not real financial observations.
The R code below calculates the mean and the sum of five numbers.
numbers <- c(12, 18, 20, 25, 30)
mean(numbers)[1] 21
sum(numbers)[1] 105
Here is a small sample data set with monthly revenue, cost, and profit.
finance <- data.frame(
Month = c("Jan", "Feb", "Mar", "Apr", "May"),
Revenue = c(120, 135, 150, 145, 170),
Cost = c(85, 90, 100, 98, 115)
)
finance$Profit <- finance$Revenue - finance$Cost
knitr::kable(
finance,
caption = "Illustrative monthly financial data"
)| Month | Revenue | Cost | Profit |
|---|---|---|---|
| Jan | 120 | 85 | 35 |
| Feb | 135 | 90 | 45 |
| Mar | 150 | 100 | 50 |
| Apr | 145 | 98 | 47 |
| May | 170 | 115 | 55 |
The chart below compares monthly revenue and cost.
barplot(
rbind(finance$Revenue, finance$Cost),
beside = TRUE,
names.arg = finance$Month,
col = c("steelblue", "orange"),
main = "Monthly Revenue and Cost",
xlab = "Month",
ylab = "Amount",
legend.text = c("Revenue", "Cost"),
args.legend = list(x = "topleft", bty = "n")
)The total profit and profit margin can be calculated as follows.
total_profit <- sum(finance$Profit)
profit_margin <- round(
100 * total_profit / sum(finance$Revenue),
1
)
total_profit[1] 232
profit_margin[1] 32.2
For this illustrative data set, total profit is 232 units and the profit margin is 32.2%.
This Quarto test combines explanatory text, executable R code, a table, and a chart in one HTML webpage.