Skip to content

Instantly share code, notes, and snippets.

@renato04
Created May 23, 2019 01:35
Show Gist options
  • Save renato04/6fbff5187b073b783f3ba06f32913180 to your computer and use it in GitHub Desktop.
Save renato04/6fbff5187b073b783f3ba06f32913180 to your computer and use it in GitHub Desktop.
Random Samples in R
# Generates random numbers uniformly
histogram(runif(1:100000))
# Probabily of one numbe given a unifom random numbers
dunif(x= 8, min= 1, max=11)
# Samples
set.seed(1)
amostra = c("T","R","I", "A", "N", "G", "U", "L", "O")
sample(x = amostra, replace = FALSE)
sample(x = amostra, replace = TRUE)
sample(x = amostra, size = 5)
sample(x = amostra, size = 10, replace= TRUE, prob = c(1, 1, 5, 1, 1, 1, 1, 1, 5))
#Workin wih arqualiy
# Dimension
dim(airquality)
# Summary
summary(airquality)
# Sample
airquality[1:10,]
# OR
head(airquality, 10)
# Determined size, random
airquality[runif(min = 1, n= 10, max=nrow(airquality)),]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment