R Markdown

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

Including Plots

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)

1. Load the bike sales data

bike_sales <- readRDS(“C:/Users/Richard/Documents/FINANCIAL DATABASE/bike_orderlines.rds”)

2. Check the structure of the data to understand its contents

str(bike_sales) head(bike_sales)

3. Extract the month and year from the date column

Assuming there’s a ‘date’ column; replace with actual date column name if different

bike_sales <- bike_sales %>% mutate(month = month(date, label = TRUE), year = year(date))

4. Calculate monthly sales

monthly_sales <- bike_sales %>% group_by(year, month) %>% summarise(total_sales = sum(sales_column_name, na.rm = TRUE)) # Replace with actual sales column name

5. Find the month with the highest sales

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)

Interpretation for marketing:

If highest_sales shows a specific peak month, this month is ideal for marketing efforts.

Load the ETF data from the CSV file

etf_data <- read_csv(“C:/Users/Richard/Documents/FINANCIAL DATABASE/MidtermDataTEJ.csv”) # Replace with actual file path

Inspect the data structure and first few rows to understand the columns

str(etf_data) head(etf_data)

Assuming columns for ‘date’, ‘closing_price’, and ‘ETF_name’ (adjust as per your actual column names)

Convert the date column to Date format if it’s not already

etf_data <- etf_data %>% mutate(date = ymd(date)) # Use appropriate date format if not YYYY-MM-DD

Filter data for ETFs 0050, 0052, and 0056

etf_filtered <- etf_data %>% filter(ETF_name %in% c(“ETF0050”, “ETF0052”, “ETF0056”))

Calculate yearly average closing prices for each ETF

yearly_avg_prices <- etf_filtered %>% group_by(ETF_name, year = year(date)) %>% summarise(avg_closing_price = mean(closing_price, na.rm = TRUE))

Display the results

print(“Yearly average closing prices for ETFs 0050, 0052, and 0056:”) print(yearly_avg_prices)