r random code code example Example: random integer in r random_x <- sample(1:10, 1) # or random_10x = sample(-1:1, size = 10, replace = T)