Variables
A variable is a named location in memory that holds a value. The name can then be used to access or modify that value.
Variables are essential in R because they allow you to store values for later use, making code easier to write, read, and maintain.
Naming Rules
- A variable name can include letters, numbers, dots(
.), and underscores(_); - A variable name can only start with a letter or a dot;
- If a variable name starts with a dot, the next character can't be a number;
- A variable name cannot be the same as a reserved keyword, such as
TRUE,FALSE,NA, etc.
Choose meaningful names that describe the data. For example, year is more descriptive than a. This improves code readability.
Assignment Syntax
To assign a value to a variable, the assignment operator = can be used.
Example
12year = 2020 cat(year)
Swipe to start coding
You want to prepare values for a deposit calculation. Save the following data into variables:
2000asinitial_money;13asinterest_rate;4asn_years.
Then, use cat() to display these values together in the same order.
Ratkaisu
Kiitos palautteestasi!
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Mahtavaa!
Completion arvosana parantunut arvoon 2.27
Variables
Pyyhkäise näyttääksesi valikon
A variable is a named location in memory that holds a value. The name can then be used to access or modify that value.
Variables are essential in R because they allow you to store values for later use, making code easier to write, read, and maintain.
Naming Rules
- A variable name can include letters, numbers, dots(
.), and underscores(_); - A variable name can only start with a letter or a dot;
- If a variable name starts with a dot, the next character can't be a number;
- A variable name cannot be the same as a reserved keyword, such as
TRUE,FALSE,NA, etc.
Choose meaningful names that describe the data. For example, year is more descriptive than a. This improves code readability.
Assignment Syntax
To assign a value to a variable, the assignment operator = can be used.
Example
12year = 2020 cat(year)
Swipe to start coding
You want to prepare values for a deposit calculation. Save the following data into variables:
2000asinitial_money;13asinterest_rate;4asn_years.
Then, use cat() to display these values together in the same order.
Ratkaisu
Kiitos palautteestasi!
single