Search
 
SCRIPT & CODE EXAMPLE
 

R

random R

# ----- For uniformly distributed (flat) random numbers -----
runif(1)
#> [1] 0.09006613

# Get a vector of 4 numbers
runif(4)
#> [1] 0.6972299 0.9505426 0.8297167 0.9779939

# Get a vector of 3 numbers from 0 to 100
runif(3, min=0, max=100)
#> [1] 83.702278  3.062253  5.388360

# Get 3 integers from 0 to 100
# Use max=101 because it will never actually equal 101
floor(runif(3, min=0, max=101))
#> [1] 11 67  1

# This will do the same thing
sample(1:100, 3, replace=TRUE)
#> [1]  8 63 64

# To generate integers WITHOUT replacement:
sample(1:100, 3, replace=FALSE)
#> [1] 76 25 52

# ----- To generate numbers from a normal distribution -----
rnorm(4)
#> [1] -2.3308287 -0.9073857 -0.7638332 -0.2193786

# Use a different mean and standard deviation
rnorm(4, mean=50, sd=10)
#> [1] 59.20927 40.12440 44.58840 41.97056

# To check that the distribution looks right, make a histogram of the numbers
x <- rnorm(400, mean=50, sd=10)
hist(x)
Comment

PREVIOUS NEXT
Code Example
R :: percent of missing data in df r 
R :: calculating RMSE, MAE, MSE, Rsquared manually in R 
R :: convert first row to header in r 
R :: how to throw an error in R 
R :: regression in r with many variables 
R :: how to create for loop through columns and count non na cells by group in r 
R :: Reorder bars in geom_bar ggplot2 by value 
R :: dataframe to r code 
R :: how to change order in bar chart r 
R :: combine ro columns in r 
R :: calculated defualt values in R function parameters 
R :: how to make the minutes zero in r 
R :: show unique R 
R :: how to bootstrap in r with resampling 
R :: dplyr mutate with conditional values 
R :: r create intervals cut 
R :: index in r 
R :: changing base group in factor in r 
R :: meaning of %% R 
R :: r alluvial chart with NA 
Rust :: rust sort vector of number descending 
Rust :: rust convert integer to string 
Rust :: convert number to string rust 
Rust :: optional arguments rust 
Rust :: get the temp directory rust 
Rust :: Rust Multithreading with a Vector of different functions 
Rust :: armanriazi•rust•oop 
Rust :: armanriazi•rust•error•E0615•attempted to take value of method `collect` on type 
Rust :: armanriazi•rust•concept•pattern•newtype 
Rust :: rust string split 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =