Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Variables | Basic Syntax and Operations
R Introduction: Part I
course content

Course Content

R Introduction: Part I

R Introduction: Part I

1. Basic Syntax and Operations
2. Basic Data Types and Vectors
3. Factors

bookVariables

Saving and reusing data effectively in programming often requires the use of variables.

To ensure clear and error-free programming, certain rules must be followed when naming variables. Here are some guidelines:

  • Variable names must not start with a number or with a period followed by a number;
  • They should not include the % symbol;
  • They must not begin with an underscore _;
  • They can start with a period if it is not followed by a number.

Choosing meaningful variable names is considered best practice. For instance, naming a variable year to store the value 2020 is more intuitive than using nondescript names like a or b. While this isn't mandatory, it significantly enhances code readability for both the author and others.

To assign a value to a variable, the assignment operator = is used. For example, year = 2020 assigns the value 2020 to the variable named year:

12
year = 2020 cat(year)
copy

Task

Regarding the deposit task, let's assign the relevant data to variables using the assignment operator:

  1. Assign the initial amount of money, 2000, to the variable named initial_money.
  2. Assign the interest rate, 13, to the variable named interest_rate.
  3. Assign the number of years, 4, to the variable named n_years.
  4. Use the cat() function to display the values of initial_money, interest_rate, and n_years in the order they were created.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 8
toggle bottom row

bookVariables

Saving and reusing data effectively in programming often requires the use of variables.

To ensure clear and error-free programming, certain rules must be followed when naming variables. Here are some guidelines:

  • Variable names must not start with a number or with a period followed by a number;
  • They should not include the % symbol;
  • They must not begin with an underscore _;
  • They can start with a period if it is not followed by a number.

Choosing meaningful variable names is considered best practice. For instance, naming a variable year to store the value 2020 is more intuitive than using nondescript names like a or b. While this isn't mandatory, it significantly enhances code readability for both the author and others.

To assign a value to a variable, the assignment operator = is used. For example, year = 2020 assigns the value 2020 to the variable named year:

12
year = 2020 cat(year)
copy

Task

Regarding the deposit task, let's assign the relevant data to variables using the assignment operator:

  1. Assign the initial amount of money, 2000, to the variable named initial_money.
  2. Assign the interest rate, 13, to the variable named interest_rate.
  3. Assign the number of years, 4, to the variable named n_years.
  4. Use the cat() function to display the values of initial_money, interest_rate, and n_years in the order they were created.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 8
toggle bottom row

bookVariables

Saving and reusing data effectively in programming often requires the use of variables.

To ensure clear and error-free programming, certain rules must be followed when naming variables. Here are some guidelines:

  • Variable names must not start with a number or with a period followed by a number;
  • They should not include the % symbol;
  • They must not begin with an underscore _;
  • They can start with a period if it is not followed by a number.

Choosing meaningful variable names is considered best practice. For instance, naming a variable year to store the value 2020 is more intuitive than using nondescript names like a or b. While this isn't mandatory, it significantly enhances code readability for both the author and others.

To assign a value to a variable, the assignment operator = is used. For example, year = 2020 assigns the value 2020 to the variable named year:

12
year = 2020 cat(year)
copy

Task

Regarding the deposit task, let's assign the relevant data to variables using the assignment operator:

  1. Assign the initial amount of money, 2000, to the variable named initial_money.
  2. Assign the interest rate, 13, to the variable named interest_rate.
  3. Assign the number of years, 4, to the variable named n_years.
  4. Use the cat() function to display the values of initial_money, interest_rate, and n_years in the order they were created.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Saving and reusing data effectively in programming often requires the use of variables.

To ensure clear and error-free programming, certain rules must be followed when naming variables. Here are some guidelines:

  • Variable names must not start with a number or with a period followed by a number;
  • They should not include the % symbol;
  • They must not begin with an underscore _;
  • They can start with a period if it is not followed by a number.

Choosing meaningful variable names is considered best practice. For instance, naming a variable year to store the value 2020 is more intuitive than using nondescript names like a or b. While this isn't mandatory, it significantly enhances code readability for both the author and others.

To assign a value to a variable, the assignment operator = is used. For example, year = 2020 assigns the value 2020 to the variable named year:

12
year = 2020 cat(year)
copy

Task

Regarding the deposit task, let's assign the relevant data to variables using the assignment operator:

  1. Assign the initial amount of money, 2000, to the variable named initial_money.
  2. Assign the interest rate, 13, to the variable named interest_rate.
  3. Assign the number of years, 4, to the variable named n_years.
  4. Use the cat() function to display the values of initial_money, interest_rate, and n_years in the order they were created.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 1. Chapter 8
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
some-alt