What if you could stop rewriting numbers and let your computer remember them perfectly for you?
Why Variable assignment (<- and =) in R Programming? - Purpose & Use Cases
Imagine you want to keep track of your daily expenses on paper. Every time you spend money, you write down the new total by adding the amount to your previous total manually.
This manual method is slow and easy to mess up. You might forget to add some expenses or write the wrong number, making your total incorrect and confusing.
Variable assignment in R lets you store values in a name, so you can update and reuse them easily without rewriting everything. It keeps your data organized and your calculations accurate.
total <- 0 # add 10 # add 5 # add 3 # manually update total each time
total <- 0 total <- total + 10 total <- total + 5 total <- total + 3
It lets you keep track of changing information easily and use it throughout your program without mistakes.
Tracking your bank account balance by updating it every time you deposit or withdraw money, so you always know how much you have.
Variables store information with a name.
Assignment operators (<- and =) put values into variables.
This makes updating and using data simple and error-free.