This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the plot. #
Load necessary libraries library(dplyr) library(lubridate)
library(readr)
bike_sales <- readRDS(“C:/Users/Richard/Documents/FINANCIAL DATABASE/bike_orderlines.rds”)
str(bike_sales) head(bike_sales)
bike_sales <- bike_sales %>% mutate(month = month(date, label = TRUE), year = year(date))
monthly_sales <- bike_sales %>% group_by(year, month) %>% summarise(total_sales = sum(sales_column_name, na.rm = TRUE)) # Replace with actual sales column name
highest_sales <- monthly_sales %>% group_by(month) %>% summarise(average_sales = mean(total_sales)) %>% arrange(desc(average_sales))
print(“Month with highest average sales:”) print(highest_sales)
etf_data <- read_csv(“C:/Users/Richard/Documents/FINANCIAL DATABASE/MidtermDataTEJ.csv”) # Replace with actual file path
str(etf_data) head(etf_data)
etf_data <- etf_data %>% mutate(date = ymd(date)) # Use appropriate date format if not YYYY-MM-DD
etf_filtered <- etf_data %>% filter(ETF_name %in% c(“ETF0050”, “ETF0052”, “ETF0056”))
yearly_avg_prices <- etf_filtered %>% group_by(ETF_name, year = year(date)) %>% summarise(avg_closing_price = mean(closing_price, na.rm = TRUE))
print(“Yearly average closing prices for ETFs 0050, 0052, and 0056:”) print(yearly_avg_prices)