Created
November 26, 2010 03:39
-
-
Save prasoonsharma/716248 to your computer and use it in GitHub Desktop.
Using R as a calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# USE R AS A CALCULATOR | |
# Comments (like this one) are indicated with a # in R | |
# Addition | |
1 + 2 | |
# Subtraction | |
3.2 - 1.8 | |
# Division | |
12/3 | |
# Multiplication | |
12 * 3 | |
# Exponential | |
12^2 | |
# Remainder of integer division (modulo) | |
12%%3 | |
# Quotient of integer division | |
10 %\% 3 | |
# Convert Float to Integer | |
as.integer(5.9) | |
# Convert String to Numeric | |
population <- "5000" | |
population | |
as.numeric(population) | |
# Log | |
log(10) | |
# Log 10 | |
log10(10) | |
# Square root | |
sqrt(2) | |
# Pi | |
pi | |
# Sin | |
sin(pi) | |
# Cos | |
cos(0.707) | |
# Tan | |
tan(1.5) | |
# Use brackets to specify sequence of calculations | |
(1 + 3) * 2.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment