-Dealing with Number
Learn the basics of working with numbers in R
#How to manage the numeric type (integer vs. double)
Numeric Types (integer vs. double):
R automatically converts integers and double for mathematical purposes
Creating Integer and Double Vectors:
By default, c() function will produce a vector of double numeric values. Create integer by placing an L after each number
# create a double datatyp
double_var <- c(5, 9.5, 89.5)
# placing an L after the values creates integers
integer_var <- c(1L, 6L, 10L)Numeric Type Test:
typeof(double_var)
## [1] "double"
typeof(integer_var)
## [1] "integer"Converting Between Integer and Double Values:
By default, using the x <- 1:10 method is integer data type. Change the datatyp with this methode:
#The different ways of generating non-random numbers
Specifing Numbers within a Sequence:
Generating Regular Sequences:
Generating Repeated Sequences:
#The different ways of generating random numbers
R has pseudo-random number generators that allow you to simulate the most common probability distributions.
Uniform numbers:
Non-uniform probability distribution have four primary functions:
r: random number generationd: density or probability mass functionp: cumulative distributionq: quantiles
Normal Distribution Numbers:
Binomial Distribution Numbers:
Poisson Distribution Numbers:
Exponential Distribution Numbers:
Gamma Distribution Numbers:
#Setting Seed Values
#Comparing Numeric Values
Comparison Operators:
Exact Equality:
Floating Point Comparison:
#Rounding numeric Values
Last updated