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 numbers under shared restrictions

As you may remember, The Food Factory creates their foods by receiving a macronutrient specification. Customers can specify whatever combination of percentages they want for each one, as long as they add up to 1. Now we are going to simulate these macronutrient percentages. This will require a little more work than the previous cases.

First, we create a function that will return numeric triples, where each number is between 0 and 1, and together they add up to 1. To accomplish this, we will use two random numbers and make the third one dependent on the first two. We will use the following mathematical fact:

This tells us to take one number as 1 - max(a, b), another as min(a, b), and the last one ...

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