0
0
R Programmingprogramming~10 mins

Numeric type in R Programming - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Numeric type
Start
Assign numeric value
Store as numeric type
Use in calculations
Output result
End
This flow shows how a numeric value is assigned, stored as a numeric type, used in calculations, and then output.
Execution Sample
R Programming
x <- 5.5
print(x)
y <- x * 2
print(y)
Assign a numeric value to x, print it, multiply by 2, and print the result.
Execution Table
StepActionVariableValueOutput
1Assign 5.5 to xx5.5
2Print xx5.55.5
3Calculate y = x * 2y11.0
4Print yy11.011
5End of code
💡 Code ends after printing y.
Variable Tracker
VariableStartAfter Step 1After Step 3Final
xundefined5.55.55.5
yundefinedundefined11.011.0
Key Moments - 2 Insights
Why does x hold 5.5 and not an integer?
Because 5.5 has a decimal point, R stores it as a numeric (double) type, as shown in step 1 of the execution_table.
What happens when we multiply x by 2?
The value of x (5.5) is multiplied by 2 to get 11, which is stored in y, as shown in step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2, what is printed?
Ax
B11
C5.5
DError
💡 Hint
Check the Output column at step 2 in the execution_table.
At which step is the variable y assigned a value?
AStep 3
BStep 2
CStep 1
DStep 4
💡 Hint
Look at the Action and Variable columns in the execution_table.
If we change x to 3, what will be the value of y at step 3?
A5.5
B6
C3
D11
💡 Hint
y is calculated as x * 2, so multiply the new x value by 2.
Concept Snapshot
Numeric type in R stores numbers with or without decimals.
Assign with <-, e.g., x <- 5.5.
Used in calculations like y <- x * 2.
Print values with print().
Decimals mean numeric (double) type.
Full Transcript
This example shows how R handles numeric types. First, we assign 5.5 to variable x. Because 5.5 has a decimal, R treats it as a numeric type. We print x, which outputs 5.5. Next, we calculate y by multiplying x by 2, resulting in 11. We print y, which outputs 11. The variables x and y change as the code runs, storing the numeric values. This demonstrates basic numeric assignment and arithmetic in R.