February 15, 2024
Open R Studio using R project(created before)
Create a R script file
save it(Use lecture number or date as name)
Do make comments in your script file
In the r script file/console, calculate \(21+21\) , \(7*6\) and \((0.3/4) × \sqrt(31360)\)
These operators are used to assign values to variables
The operators <-
and =
can be used most of the time interchangeably
The <<-
operator is used for assigning to variables in the parent environments (more like global assignments)
right ward operators, however rarely used
Operator | Descriptor |
---|---|
<- , <<- , = |
Leftward Assignemnt |
-> , ->> |
Rightward Assignment |
Operators | Description |
---|---|
+ |
Addition |
- |
Subtraction |
* |
Multiplication |
/ |
Division |
^ |
Exponential |
%% |
Modulus(Remainder Division) |
Relational operators are used to compare between values
Operators | Description |
---|---|
< |
Less than |
> |
Greater than |
<= |
Less than or equal to |
>= |
Greater than or equal to |
== |
Equal to |
!= |
Not equal to |
Logical operators are used to carry out Boolean operations like AND, OR etc
Operators &
and |
perform element-wise operation producing result having length of the longer operand
But &&
and ||
examines only the first element of the operands resulting into a single length logical vector
Zero is considered FALSE and non-zero numbers are taken as TRUE
&&
→(logical AND)
Compares two expressions and returns true if both evaluate to true.
Returns false only if both expressions are false.
true &&
false → Evaluates false because the second is false
false &&
true → Evaluates false because the first is false
true &&
true → Evaluates true because both are true
false &&
false → Evaluates false because both are false
||
→(logical OR)
Compares two expressions and returns true if one or both evaluate to true.
Returns false only if both expressions are false.
true ||
false → Evaluates true because the first is true
false ||
true → Evaluates true because the second is true
true ||
true → Evaluates true because both are true
false ||
false → Evaluates false because both are false
x
in the last example is changeded to 20, 40 and 66, what will be the results?THANKS