Skip to Content
R Programming By Example
book

R Programming By Example

by Omar Trejo Navarro
December 2017
Beginner to intermediate
470 pages
12h 29m
English
Packt Publishing
Content preview from R Programming By Example

Simulating categorical values using factors

The random_levels() function simulates n categorical values by sampling the levels provided with replacement (controlled by the third parameter, which is sent as TRUE). You can think about the levels as an array of strings, each of which is a possible value for the simulation. These levels will come from the categories defined for factor variables in the data frame (PROTEIN_SOURCE, STORE, DELIVERY, STATUS, and PAID). A sample with replacement means that every time we pick one of the values from the levels object, we return it so that we can pick it again later. Sampling without replacement only makes sense when you want a number of samples that is smaller than the total amount of values available, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Efficient R Programming

Efficient R Programming

Colin Gillespie, Robin Lovelace
R Programming

R Programming

Jared P. Lander

Publisher Resources

ISBN: 9781788292542Supplemental Content