Use of R Language as Simple Calculator & Mathematical Operator
In Windows Operating system, The R installer will have created an icon for R on desktop and a Start Menu item. Double click the R icon to start the R Program; R will open the console, to type the R commands. The greater than sing (>) in console is the prompt symbol. In this tutorial we will use R language as calculator, by typing some simple mathematical expressions at the prompt (>). Anything that can be computed on a pocket calculator can also be computed at the R prompt. After entering the expression on prompt, you have to press the Enter key from keyboard to execute the command. Some examples are as follows >1+2 >1-2 >1*2 >1/2 > 1%/ %2 > 2ˆ1 > 31 %% 7 #add two or more numbers #subtracts two or more numbers #multiply two or more numbers #divides two more more numbers #gives the integer part of the quotient #gives exponentiation #gives the remainder after division
These operators also works ne for complex numbers. Upon pressing the enter key, the result of expression will appear, prexed by a number in square bracket:
> 1 + 2 [1] 54
The [1] indicates that this is the rst result from the command. Some advance calculations that are available in scientic calculators can also be easily done in R for example
1
Visit: http://itfeature.com
Use of R Language as Calculator > sqrt(5) > log(10) > sin(45) > pi > exp(2) > log10(5) > factorial(5) > abs(1/-2) > 2*pi/360 #Square Root of a number #Natural log of a number #Trignometric function (sin function) #pi value 3.141593 #antilog, e raised to a power #Log of a number base 10 #Factorial of a number e.g 5! #Absolute values of a number
#Number of radian in one Babylonian degree of a circle
Remember R prints all very large or very small numbers in scientic notation. R language also make use of parentheses for grouping operations to follow the rules for order of operations. for example > 1-2/3 #It rst