Function definition
📖 Scenario: You are helping a small bakery keep track of how many cookies they bake each day. They want to use a simple function to calculate the total cookies baked over several days.
🎯 Goal: Create a function in R that adds two numbers representing cookies baked on two different days, then use it to find the total cookies baked.
📋 What You'll Learn
Create a function called
add_cookies that takes two parameters: day1 and day2.The function should return the sum of
day1 and day2.Create two variables
cookies_day1 and cookies_day2 with values 50 and 70 respectively.Call the function
add_cookies with cookies_day1 and cookies_day2 as arguments and store the result in total_cookies.Print the value of
total_cookies.💡 Why This Matters
🌍 Real World
Bakeries and small businesses often need simple calculations to track daily production or sales. Functions help automate these calculations.
💼 Career
Understanding how to define and use functions is a key skill for data analysis, automation, and software development jobs.
Progress0 / 4 steps