[1] "This is my first assignment"
M01-2 Introduction to Literate Programming-Application Assignment
Introduction:
Hello, this document contains all 10 completed exercises for M101-2 Introduction to Literate Programming Assignment for IBM 6530 Marketing Analytics class at Cal Poly Pomona for the Masters of Science: Digital Marketing & Analytics program. Each exercise demonstrates basic R coding, data manipulation, and visualization skills duirng Quarto.
1 Ex 1. Create a variable X
Create a variable called
Xand assign the text “This is my first assignment” to it.
2 Ex 2. Adding Texts in Base R
Add two pieces of text together using
paste()andpaste0()in Base R.
3 Ex 3. Create and modify a vector
Create a vector called
Ywith the numbers 2, 3, 4, and 5. Next, multiply the vector by 2 and save it asYagain.
4 Ex 4. Print variables X and Y
Print both the variable
Xand the vectorY.
5 Ex 5. Maximum and minimum of Y
Show the maximum and minimum value of the vector
Ythat you created.
6 Ex 6. Plot unemployment duration over time
Using the
economicsdataset, create a line plot ofuempmedover time usingggplot2.
7 Ex 7. Add labels to the plot
Add a title and axis labels to the line plot of
uempmedover time.
8 Ex 8. Filter the economics dataset
Filter the
economicsdataset to only include data from the year 2000, and print the first 6 rows.
# Load dplyr for filtering
library(dplyr)
# Filter for the year 2000 and show first 6 rows
economics %>%
filter(format(date, "%Y") == "2000") %>%
head()# A tibble: 6 × 6
date pce pop psavert uempmed unemploy
<date> <dbl> <dbl> <dbl> <dbl> <dbl>
1 2000-01-01 6535. 280976 5.4 5.8 5708
2 2000-02-01 6620. 281190 4.8 6.1 5858
3 2000-03-01 6686. 281409 4.5 6 5733
4 2000-04-01 6671. 281653 5 6.1 5481
5 2000-05-01 6708. 281877 4.9 5.8 5758
6 2000-06-01 6744. 282126 4.9 5.7 5651
9 Ex 9. Calculate mean unemployment duration for 2000
Using the filtered data from Exercise 8, calculate the mean of
uempmedfor the year 2000.
10 Ex 10. Reflection
Write a short reflection (1–2 sentences) about what you learned in this assignment. Save it as a variable called
reflectionand print it.
# Create a reflection text
reflection <- "In this assignment, I learned how to use Quarto, write clean R code, and create visualizations with ggplot2. I also practiced filtering and summarizing data."
# Print the reflection
reflection[1] "In this assignment, I learned how to use Quarto, write clean R code, and create visualizations with ggplot2. I also practiced filtering and summarizing data."
Conclusion:
This assignment was helpful for me to practice writing R codes, using Quarto for literate programming for the first time, summarizing data and creating visualizations with the different packages we used.