R Programming
R Random Forest Tutorial with Example
What is Random Forest in R? Random forests are based on a simple idea: 'the wisdom of the crowd'....
An operator refers to a symbol that instructs the compiler to perform a specific logical or mathematical manipulation. The operator performs the operation on the provided operands. Microsoft VB.Net comes with various types of operators. We will be discussing these in this tutorial.
In this tutorial, you will learn-
You can use arithmetic operators to perform various mathematical operations in VB.NET. They include:
| Symbol | Description |
| ^ | for raising an operand to the power of another operand |
| + | for adding two operands. |
| - | for subtracting the second operand from the first operand. |
| * | for multiplying both operands. |
| / | for dividing an operand against another. It returns a floating point result. |
| \ | for dividing an operand against another. It returns an integer result. |
| MOD | known as the modulus operator. It returns the remainder after division. |
Let us demonstrate how to use these using an example:
Step 1) Create a new console application. To know this, visit our previous tutorial on Data Types and Variables.
Step 2) Add the following code:
Module Module1
Sub Main()
Dim var_w As Integer = 11
Dim var_x As Integer = 5
Dim var_q As Integer = 2
Dim var_y As Integer
Dim var_z As Single
var_y = var_w + var_z
Console.WriteLine(" Result of 11 + 5 is {0} ", var_y)
var_y = var_w - var_x
Console.WriteLine(" Result of 11 - 5 is {0} ", var_y)
var_y = var_w * var_x
Console.WriteLine(" Result of 11 * 5 is {0} ", var_y)
var_z = var_w / var_x
Console.WriteLine(" Result of 11 / 5 is {0}", var_z)
var_y = var_w \ var_x
Console.WriteLine(" Result of 11 \ 5 is {0}", var_y)
var_y = var_w Mod var_x
Console.WriteLine(" Result of 11 MOD 5 is {0}", var_y)
var_y = var_x ^ var_x
Console.WriteLine(" Result of 5 ^ 5 is {0}", var_y)
Console.ReadLine()
End Sub
End Module
Step 3) Click the Start button to execute the code. You should get the following window:
Here is a screenshot of the code:
Explanation of Code:
These operators are used for making comparisons between variables. They include the following:
| Comparison Operators | Details |
| = | for checking whether the two operands have equal values or not. If yes, the condition will become true. |
| <> | for checking if the value of the left operand is greater than that of the right operand. then condition will become true. |
| > | for checking whether the value of the left operand is less than that of the right operand. If yes, the condition will become true. |
| < | for checking whether the value of the left operand is greater than or equal to that of the right operand. If yes, the condition will become true. |
| >= | for checking whether the two operands have equal values or not. If yes, the condition will become true. |
| <= | for checking whether the value of the left operand is less than or equal to that of the right operand. If yes, the condition will become true. |
Let us demonstrate how to use these using an example:
Step 1) Create a new console application. If you don't know how to do it, visit our previous tutorial on Data Types and Variables.
Step 2) Add the following code:
Module Module1
Sub Main()
Dim x As Integer = 11
Dim y As Integer = 5
If (x = y) Then
Console.WriteLine("11=5 is True")
Else
Console.WriteLine(" 11=5 is False")
End If
If (x < y) Then
Console.WriteLine(" 11<5 is True")
Else
Console.WriteLine(" 11<5 is False")
End If
If (x > y) Then
Console.WriteLine(" 11>5 is True")
Else
Console.WriteLine(" 11>5 is False")
End If
x = 3
y = 7
If (x <= y) Then
Console.WriteLine(" 3<=7 is True")
End If
If (y >= x) Then
Console.WriteLine(" 7>=3 is True")
End If
Console.ReadLine()
End Sub
End Module
Step 3) Click the Start button from the toolbar to run the code. You should get the following window:
We have used the following code:
Explanation of Code:
These operators help us in making logical decisions.
They include:
| Logical/ Bite wise Operator | Descriptions |
| And | known as the logical/bitwise AND. Only true when both conditions are true. |
| Or | known as the logical/bitwise OR. True when any of the conditions is true. |
| Not | The logical/bitwise NOT. To reverse operand's logical state. If true, the condition becomes False and vice versa. |
| Xor | bitwise Logical Exclusive OR operator. Returns False if expressions are all True or False. Otherwise, it returns True. |
| AndAlso | It is also known as the logical AND operator. Only works with Boolean data by performing short-circuiting. |
| OrElse | It is also known as the logical OR operator. Only works with Boolean data by performing short-circuiting. |
| IsFalse | Determines whether expression evaluates to False. |
| IsTrue | Determines whether expression evaluates to True. |
Let us demonstrate how to use these operators using an example:
Step 1) Create a new console application. If you don't know how to do it, visit our previous tutorial on Data Types and Variables.
Step 2) Add the following code:
Module Module1
Sub Main()
Dim var_w As Boolean = True
Dim var_x As Boolean = True
Dim var_y As Integer = 5
Dim var_z As Integer = 20
If (var_w And var_x) Then
Console.WriteLine("var_w And var_x - is true")
End If
If (var_w Or var_x) Then
Console.WriteLine("var_w Or var_x - is true")
End If
If (var_w Xor var_x) Then
Console.WriteLine("var_w Xor var_x - is true")
End If
If (var_y And var_z) Then
Console.WriteLine("var_y And var_z - is true")
End If
If (var_y Or var_z) Then
Console.WriteLine("var_y Or var_z - is true")
End If
'Only logical operators
If (var_w AndAlso var_x) Then
Console.WriteLine("var_w AndAlso var_x - is true")
End If
If (var_w OrElse var_x) Then
Console.WriteLine("var_w OrElse var_x - is true")
End If
var_w = False
var_x = True
If (var_w And var_x) Then
Console.WriteLine("var_w And var_x - is true")
Else
Console.WriteLine("var_w And var_x - is not true")
End If
If (Not (var_w And var_x)) Then
Console.WriteLine("var_w And var_x - is true")
End If
Console.ReadLine()
End Sub
End Module
Step 3) Run the code by clicking the Start button from the toolbar. You will get the following window:
Here are screenshots of the above code:
Explanation of Code:
These operators are used for performing shift operations on binary values.
| Bit-shit operatiors | Details |
| And | Known as the Bitwise AND Operator. It copies a bit to result if it is found in both operands. |
| Or | Known as the Binary OR Operator. It copies a bit if found in either operand. |
| Xor | The Binary XOR Operator. For copying a bit if set in one of the operands rather than both. |
| Not | It is known as the Binary Ones Complement Operator. It is a unary operator that 'flips' the bits. |
Let us demonstrate how to use these operators using an example:
Step 1) Create a new console application. If you don't know how to do it, visit our previous tutorial on Data Types and Variables.
Step 2) Add the following code:
Module Module1
Sub Main()
Dim w As Integer = 50
Dim x As Integer = 11
Dim y As Integer = 0
y = w And x
Console.WriteLine("y = w And x is {0}", y)
y = w Or x
Console.WriteLine("y = w Or x is {0}", y)
y = w Xor x
Console.WriteLine("y = w Xor x is {0}", y)
y = Not w
Console.WriteLine("y = Not w is {0}", y)
Console.ReadLine()
End Sub
End Module
Step 3) Run the code by clicking the Start button. You should get the following window:
Here is a screenshot of the code:
Explanation of Code:
| Assignment Operator | Details |
| = |
|
| += |
|
| = |
|
| *= |
|
Let us demonstrate how to use these operators using an example:
Step 1) Create a new console application. If you don't know how to do it, visit our previous tutorial on Data Types and Variables.
Step 2) Add the following code:
Module Module1
Sub Main()
Dim x As Integer = 5
Dim y As Integer
y = x
Console.WriteLine(" y = x gives y = {0}", y)
y += x
Console.WriteLine(" y += x gives y = {0}", y)
y -= x
Console.WriteLine(" y -= x gives y = {0}", y)
y *= x
Console.WriteLine(" y *= x gives y = {0}", y)
Console.ReadLine()
End Sub
End Module
Step 3) Now, run the code by clicking the Start button from the toolbar. You should get the following window:
The following code has been used:
Explanation of Code:
There are other operators supported by VB.NET. Let us discuss them:
| Miscellaneous Operators | Details |
| GetType | This operator gives the Type of objects for a specified expression. |
| Function Expression |
|
For example:
Step 1) Create a new console application. If you don't know how to do it, visit our previous tutorial on Data Types and Variables.
Step 2) Add the following code:
Module Module1
Sub Main()
Dim x As Integer = 5
Console.WriteLine(GetType(Integer).ToString())
Console.WriteLine(GetType(String).ToString())
Console.WriteLine(GetType(Double).ToString())
Dim trippleValue = Function(val As Integer) val * 3
Console.WriteLine(trippleValue(2))
Console.WriteLine(If(x >= 0, "Positive", "Negative"))
Console.ReadLine()
End Sub
End Module
Step 3) Run the code by clicking the Start button on the toolbar. You should get the following window:
We have used the following code:
Explanation of Code:
What is Random Forest in R? Random forests are based on a simple idea: 'the wisdom of the crowd'....
Tata Consultancy Services is an Indian multinational information technology company headquartered...
What is MVC? The MVC framework is an architectural pattern that separates an applications into...
Software engineering is defined as a process of analyzing user requirements and then designing,...
Monitoring the temperature of the processor is essential because it can affect the performance of...
Defragmentation is a process that physically organizes the content of your hard disk and stores...