R Workout 6 - Creation of time dimension tables

image

We all know the advantages of working with real-world data sets. But sometimes we want to craft the data to fit our needs, and we want to do it in as dynamic a way as possible.

That is what this exercise will serve.

Task 1.

Find the R function that will indicate the system date. I am preparing this exercise on 2023-05-28 so this is the date that R should return.

image

Task 2.

Generate a sequence of dates extending from the system date 6 days back to the system date. In my case, it will be the following series:

Task 3

Turn this series into a Column data frame named Calendar and add the following columns. Let’s define Monday as first day of week. (I needed to rerun it on 29.05, system days changes)

Task 4

Use the variable FirstDay ← as.Date(“2023-01-01”) to generate a list of the first days of the first 3 months of 2023

image

Task 5

Find the function that fills the gaps between the 3 dates generated in the previous task. This should give a list of 60 days. Create data frame with dates as column.

image

Add a StockPrice Column to list random positive values. There must be as many as dates.

image

Extra task:

Create a plot presenting evolution of stock price.

Feel free to use R online:** **https://rdrr.io/

image

Solution will be posted on 04.06.2023

Hello All, please see my explanation:

Task 1.

Task 2.

Task 3.

Task 4.

Task 5

Extra task: