Generate systematic and random data

Empty objects

[1] 0 0 0 0 0
     [,1]
[1,]    0
[2,]    0
[3,]    0
[4,]    0
[5,]    0
[1] "" "" "" "" ""
[[1]]
NULL

[[2]]
NULL

[[3]]
NULL

[[4]]
NULL

[[5]]
NULL

Systematic numerical sequences

Ordered sequences

[1] 20 21 22 23 24 25 26
[1] 26 25 24 23 22 21 20
[1] -4 -3 -2 -1  0  1  2
[1] -4 -3 -2
[1]  2  4  6  8 10 12
[1]  2  4  6  8 10
[1]  0.00 -0.25 -0.50 -0.75 -1.00
[1] 1 2 3 4 5 6
[1] 0
[1] 1 0
integer(0)

Repeated sequences

 [1] 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3
[1] "A" "A" "B" "B" "B" "C" "C" "C" "C"
 [1] 18 18 20 20 30 30 24 24 23 23 21 21

Random data

Strictly, the data is pseudorandom. There are several options for the random number generator, see RNGkind(). Use set.seed() to set the state of the RNG. This allows to replicate the following sequence of numbers. Copy .Random.seed into your own object to save the current state of the RNG. Don’t modify .Random.seed.

Sample from an urn

 [1] 3 6 3 2 2 6 3 5 4 6 6 1 2 3 5 3 3 1 4 1
[1] "rot"   "rot"   "blau"  "gruen" "blau"  "gruen" "rot"   "gruen"
[1] 4 8
[1] 6 1 3 5 4 8 2 7

Data from random variables with different distributions

[1] 2.844227 1.762224 1.694030 2.165170 3.329812
 [1] 1 3 0 1 2 0 2 1 0 2 3 1 2 0 1 1 2 1 2 2
[1] 9.183538 8.622633 8.072239 5.787448
[1] 104.29823  81.69232 106.51826 112.00265  97.54104 118.64378
[1]  0.07261917  1.83920988  1.59345974  0.11567864 -0.56678656
[1] 2.9532047 0.4913562 7.5093655 0.6704753 0.4034911

See ?Distributions for more distribution types. Even more information can be found in CRAN task view Probability Distributions.

Get the article source from GitHub

R markdown - markdown - R code - all posts