Saturday, April 29, 2023

R Tutorial Playlist - Random values

Don't forget that there is no such a thing as random value in computer technology. With random number generating functions we are actually getting numbers that look random from human perspective. Those numbers are created using complex calculations with computer time as the base or seed value. R has multiple functions for that purpose.

 runif(a, b, d)

  • a is number of results we want to receive from this function
  • b is bottom limit
  • d is upper limit
This function return floating point numbers, so if you want integer results, wrap this with as.integer() function.

fnorm(a, b, d)

  • a is number of results we want to receive from this function
  • b is mean value, means value that is going to be central point around which rest of values are going to revolve.
  • d is standard deviation, means how far from mean value our values can step away.
seed(a)

If you use seed function, and provide some number as argument, you are going to receive from that moment on, all the same values from random functions. Function seed, overrides regular behavior of random number generating functions. When you use it, from that moment, seed or source value for calculations is not going to be computer time any more, but value you have provided as argument.

sample(c(...), b)

  • c(...) is collection of elements from where this function is going to pick results.
  • b is number of how many elements we want to retrieve from function sample.

For video tutorial, check the link below


No comments:

Post a Comment