0
0
R Programmingprogramming~30 mins

Parameterized reports in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Parameterized Reports in R
📖 Scenario: You work in a small bookstore. You want to create a report that shows sales data for a specific month. Instead of making a new report every time, you will make a parameterized report that can show data for any month you choose.
🎯 Goal: Build a simple R script that uses a parameter (month) to filter sales data and then prints the total sales for that month.
📋 What You'll Learn
Create a data frame called sales_data with columns month and sales and exact values.
Create a variable called selected_month to hold the month to filter.
Use a filter to select rows from sales_data where month matches selected_month.
Calculate the total sales for the selected month and store it in total_sales.
Print the total sales with a clear message.
💡 Why This Matters
🌍 Real World
Stores and businesses often need reports filtered by dates or categories. Parameterized reports save time and avoid repeating work.
💼 Career
Data analysts and business intelligence professionals use parameterized reports to quickly generate insights for different time periods or segments.
Progress0 / 4 steps
1
Create the sales data frame
Create a data frame called sales_data with two columns: month and sales. Use these exact values: months are "January", "February", "March", "April", and sales are 150, 200, 170, 220 respectively.
R Programming
Need a hint?

Use data.frame() with two vectors named month and sales.

2
Set the selected month parameter
Create a variable called selected_month and set it to the string "March".
R Programming
Need a hint?

Assign the string "March" to selected_month.

3
Filter data and calculate total sales
Create a variable called filtered_data that contains only rows from sales_data where month equals selected_month. Then create a variable called total_sales that sums the sales column of filtered_data.
R Programming
Need a hint?

Use sales_data[sales_data$month == selected_month, ] to filter rows and sum() to add sales.

4
Print the total sales
Write a print() statement that outputs the text: Total sales in March: 170 using the variable total_sales and selected_month.
R Programming
Need a hint?

Use paste() inside print() to combine text and variables.