Basic arithmetic operations and variables
Basic Arithmetic Operations and Variables Arithmetic operations and variables are fundamental building blocks of data science and statistical analysis. These...
Basic Arithmetic Operations and Variables Arithmetic operations and variables are fundamental building blocks of data science and statistical analysis. These...
Arithmetic operations and variables are fundamental building blocks of data science and statistical analysis. These concepts allow us to manipulate and analyze numerical data effectively.
Basic Arithmetic Operations:
Addition (+): Adding two numbers together. For example, 5 + 3 = 8.
Subtraction (-): Subtracting one number from another. For example, 10 - 3 = 7.
Multiplication (*): Multiplying two numbers together. For example, 5 * 3 = 15.
Division (/): Dividing two numbers by each other. For example, 10 / 2 = 5.
Variables:
A variable is a named memory location that stores a single numerical value. We can assign values to variables using the = sign. For example:
r
age <- 25
salary <- 50000
Using Variables in Arithmetic Operations:
Once a variable is defined, we can use it in arithmetic operations. For example:
r
age_diff <- age - 18
salary_change <- salary * 0.1
Variables and DataFrames:
Variables are also essential in dataframes, which are organized collections of data. Dataframes provide a powerful way to store, analyze, and manipulate data in R.
r
df <- data.frame(age = c(25, 30, 35), salary = c(50000, 55000, 60000))
age_difference <- dfage[1]
By understanding basic arithmetic operations and variables, we can perform various data manipulations and analysis tasks with greater efficiency and clarity