Logical operations are those operations that as final result have one of two values; TRUE of FALSE.
Whenever you ask R something like
10>1
or
12<52
as result R is going to print FALSE as in the first case or TRUE as in the second case.
With command %in% you can ask whether some element is contained in an array like:
12 %in% c(3, 12, 26)
and in this case our result is going to be TRUE because 12 is contained in our array.
There are operators like ||- means 'or', and &&- means 'and' that allow you to combine conditions like:
12<10 || 15>5
12<10 && 15>5
In first case 'or' operator needs only one condition to be fulfilled in order for result to be TRUE, while in case of 'and' operator, you need to fulfill both conditions in order for result to be TRUE, what is not in our case.
And at the end, there is ! operator that simply means 'not'. If you put ! in front of any condition, result of that condition is going to be reversed.
!(1>10)
One is greater than ten but presence of operator 'not' in front, is going to reverse result from FALSE to TRUE.
Please check our YouTube video for more.
No comments:
Post a Comment