vendredi 31 mars 2017

R: split vector intro more vectors with constrains

Im working on a mealplan and I need some advice on how to split the Daily intake into several meals. I have a vector where each element represents # of grams of different foods that a person should eat in order to meet his/her Daily intake of protein, carbs, fat, fiber..etc.

The vector looks as such:

intake <-  Salmon                 Chicken                   Pesto                  Butter 
         162.573720               96.262731               48.415283                4.560707 
            Yoghurt                Couscous              Boiled Egg                   Apple 
         190.233090              518.741711              198.049714                0.000000 
            Avocado                Broccoli              Grapefruit Quark / Kesella Natural 
           0.000000              350.000000                0.000000              217.450103 
            Oatmeal 
          67.820707 

This has lenght 13. I also have a matrix X with all the nutritional facts about each food type, it looks like this:

        Salmon Chicken   Pesto Butter Yoghurt Couscous Boiled Egg  Apple Avocado Broccoli Grapefruit
protein   0.18   0.231 0.12740  0.004  0.0342   0.0379     0.1225 0.0000  0.0194   0.0350      0.007
fat       0.12   0.010 0.53850  0.820  0.0300   0.0016     0.0973 0.0005  0.1960   0.0027      0.001
carbs     0.00   0.000 0.04080  0.005  0.0484   0.2182     0.0040 0.1058  0.0170   0.0312      0.070
fibre     0.00   0.000 0.00218  0.000  0.0000   0.0140     0.0000 0.0232  0.0475   0.0310      0.019
Greens    0.00   0.000 0.00000  0.000  0.0000   0.0000     0.0000 0.0000  1.0000   1.0000      0.000
        Quark / Kesella Natural Oatmeal
protein                   0.127   0.133
fat                       0.001   0.070
carbs                     0.036   0.576
fibre                     0.000   0.100
Greens                    0.000   0.000

Lastly, I have (0/1)- vectors that indicate if the food source is considered a "breakfast" or not. The same goes for "lunch", "dinner" and "snack".

I want to split the vector "intake" into meals that one eats throughout the day. My first idea was to simply take the dot product of intake*breakfast to get all the Foods that are considered breakfast and just eat them. This method does not give very reasonable answers since It may give way to much food to eat for breakfast and almost nothing left for the rest of the meals.

So lets say someone eats 5 meals a day;

I want to split the intake vector into 5 separate vectors, with the Foods that are considered breakfast to go in the new breakfast-vector. Also, I want to be able to adjust how much of every food that goes in each vector: such as

Default (Breakfast 50% Protein or lower, 10% Fat or higher, 40% Carbohydrates or lower, Evening Snack 70% Protein or lower, 25% Fat or higher, 5% Carbohydrates or lower).

So that I can adjust so that one eats a lot of protein for breakfast and a lot of carbs Before they work out.

Any help is grealy appreciated :)

Aucun commentaire:

Enregistrer un commentaire