Thanks, I'll post my suggestion in a little while.
OK, here is the full Excel-like approach I had in mind, applied to the original data. (The full reprex is available at the bottom of this post, where it can be copied with a single click of the copy icon.)
original data, saved as table "mac" (click to access)
structure(list(Buc = c(302, 296, 304, 240, 385, 302, 322, 306,
357, 295, 320, 315, 218, 270, 280, 360, 288, 294, 308, 283, 302,
209, 312, 210, 314, 305, 195, 279, 229, 294, 310, 173, 306, 308,
238, 268, 227, 200, 339, 198, 94, 309, 198, 308, 294, 192, 294,
318, 268, 268, 208, 240, 313, 316, 318, 314, 297, 340, 340, 340,
340, 326, 295, 320, 340, 340, 67, 99, 135, 64, 126, 318, 316,
315, 314, 316, 316, 300, 308, 316, 313, 306, 191, 190, 195, 318,
199, 316, 316, 312, 314, 306, 316, 316, 310, 315, 316, 288, 314,
316, 314, 269, 315, 314, 302, 307, 316, 313, 288, 339, 354, 70,
280, 316, 304, 303, 299, 247, 305, 315, 322, 114, 308, 303, 309,
294, 325, 200, 198), MT = c(1884.48, 1847.4, 1869.96, 1497.6,
2194.5, 1887.5, 2019, 1915, 2177, 1874, 1952, 1978, 1382, 1385,
1747, 2208, 1805, 1843.38, 1931.16, 1768, 1893.5, 1308.3, 1953,
1331.4, 1978.2, 1930.65, 1234.35, 1766.07, 1454.15, 1902.18,
1984, 1098.55, 1943.1, 1955.8, 1511.3, 1688.4, 1430, 1276, 2148,
1251, 592, 1945, 1260, 1931.16, 1878.66, 1194.24, 1878.66, 2032.02,
1666, 1666, 1144, 1497.6, 1972, 1987, 1996, 1984.5, 1856.25,
2176, 2176, 2176, 2125, 2038, 1843.5, 2000, 2125, 2125, 522,
504, 857, 400, 787.5, 2054.28, 2028.72, 2025.45, 2019.02, 2038.2,
2044.52, 1935, 1989, 2039, 2019, 1964.52, 1230.04, 1229.3, 1251.9,
2060.64, 1287, 2022.4, 2022.4, 1996.8, 2009.6, 1958.4, 2022.4,
2022.4, 1984, 2031, 2038.2, 1857.6, 2025.3, 2047, 2009.6, 1748.5,
2047.5, 2041, 1917.7, 1943.31, 2006.6, 1987.55, 1854.7, 2125.53,
2194.8, 525, 1773.8, 2005.6, 1930.4, 1920, 1894.7, 1568.45, 1933.7,
2000.25, 2044.7, 570, 1925, 1900, 1935, 1885.06, 2040.5, 1274,
1266.6), Kg = c(2619, 2568, 2599, 2082, 3050, 2624, 2806, 2662,
3026, 2605, 2713, 2749, 1921, 1925, 2428, 3069, 2509, 2562, 2684,
2458, 2632, 1819, 2715, 1851, 2750, 2684, 1716, 2455, 2021, 2644,
2758, 1527, 2701, 2719, 2101, 2347, 1988, 1774, 2986, 1739, 823,
2704, 1751, 2684, 2611, 1660, 2611, 2825, 2316, 2316, 1590, 2082,
2741, 2762, 2774, 2758, 2580, 3025, 3025, 3025, 2954, 2833, 2562,
2780, 2954, 2954, 726, 701, 1191, 556, 1095, 2855, 2820, 2815,
2806, 2833, 2842, 2690, 2765, 2834, 2806, 2731, 1710, 1709, 1740,
2864, 1789, 2811, 2811, 2776, 2793, 2722, 2811, 2811, 2758, 2823,
2833, 2582, 2815, 2845, 2793, 2430, 2846, 2837, 2666, 2701, 2789,
2763, 2578, 2954, 3051, 730, 2466, 2788, 2683, 2669, 2634, 2180,
2688, 2780, 2842, 792, 2676, 2641, 2690, 2620, 2836, 1771, 1761
)), row.names = c(NA, -129L), class = "data.frame") -> mac
library(tidyverse)
# verify that data types are numeric
mac %>% as_tibble()
#> # A tibble: 129 × 3
#> Buc MT Kg
#> <dbl> <dbl> <dbl>
#> 1 302 1884. 2619
#> 2 296 1847. 2568
#> 3 304 1870. 2599
#> 4 240 1498. 2082
#> 5 385 2194. 3050
#> 6 302 1888. 2624
#> 7 322 2019 2806
#> 8 306 1915 2662
#> 9 357 2177 3026
#> 10 295 1874 2605
#> # ℹ 119 more rows
# add columns to create mac1 table
mac %>%
mutate(
Lung = sample(x = c(216,213,184), size = 129, replace = TRUE),
medie = round(MT / Buc, 2),
Pcs = floor((medie * 1000 - 200) / Lung),
CTT = MT / (Buc * Lung * Pcs / 1000),
util = (Buc * Lung * Pcs / 1000)
) -> mac1
# view portion of mac1 table
mac1 %>% head()
#> Buc MT Kg Lung medie Pcs CTT util
#> 1 302 1884.48 2619 213 6.24 28 1.046278 1801.128
#> 2 296 1847.40 2568 213 6.24 28 1.046482 1765.344
#> 3 304 1869.96 2599 216 6.15 27 1.054730 1772.928
#> 4 240 1497.60 2082 216 6.24 27 1.069959 1399.680
#> 5 385 2194.50 3050 216 5.70 25 1.055556 2079.000
#> 6 302 1887.50 2624 213 6.25 28 1.047954 1801.128
# this is only so results can be seen in post: remove to use full mac1 table
mac1 <- mac1 %>% head()
# set the number of iterations desired
num_iterations <- 2
# create list with num_iterations copies of mac1
mac1 %>%
list() %>%
rep(num_iterations) -> mac1_copied
# view list
mac1_copied
#> [[1]]
#> Buc MT Kg Lung medie Pcs CTT util
#> 1 302 1884.48 2619 213 6.24 28 1.046278 1801.128
#> 2 296 1847.40 2568 213 6.24 28 1.046482 1765.344
#> 3 304 1869.96 2599 216 6.15 27 1.054730 1772.928
#> 4 240 1497.60 2082 216 6.24 27 1.069959 1399.680
#> 5 385 2194.50 3050 216 5.70 25 1.055556 2079.000
#> 6 302 1887.50 2624 213 6.25 28 1.047954 1801.128
#>
#> [[2]]
#> Buc MT Kg Lung medie Pcs CTT util
#> 1 302 1884.48 2619 213 6.24 28 1.046278 1801.128
#> 2 296 1847.40 2568 213 6.24 28 1.046482 1765.344
#> 3 304 1869.96 2599 216 6.15 27 1.054730 1772.928
#> 4 240 1497.60 2082 216 6.24 27 1.069959 1399.680
#> 5 385 2194.50 3050 216 5.70 25 1.055556 2079.000
#> 6 302 1887.50 2624 213 6.25 28 1.047954 1801.128
# perform parallel computations in each copy of mac1
mac1_copied %>%
map(
~ .x %>%
mutate(
V = sample(x = c(216,213,184), size = nrow(.x), replace = TRUE),
W = floor((medie * 1000 - 200) / V),
X = Buc * V * W)
) -> mac1_copied
# view effect
mac1_copied
#> [[1]]
#> Buc MT Kg Lung medie Pcs CTT util V W X
#> 1 302 1884.48 2619 213 6.24 28 1.046278 1801.128 216 27 1761264
#> 2 296 1847.40 2568 213 6.24 28 1.046482 1765.344 184 32 1742848
#> 3 304 1869.96 2599 216 6.15 27 1.054730 1772.928 216 27 1772928
#> 4 240 1497.60 2082 216 6.24 27 1.069959 1399.680 184 32 1413120
#> 5 385 2194.50 3050 216 5.70 25 1.055556 2079.000 184 29 2054360
#> 6 302 1887.50 2624 213 6.25 28 1.047954 1801.128 184 32 1778176
#>
#> [[2]]
#> Buc MT Kg Lung medie Pcs CTT util V W X
#> 1 302 1884.48 2619 213 6.24 28 1.046278 1801.128 216 27 1761264
#> 2 296 1847.40 2568 213 6.24 28 1.046482 1765.344 184 32 1742848
#> 3 304 1869.96 2599 216 6.15 27 1.054730 1772.928 216 27 1772928
#> 4 240 1497.60 2082 216 6.24 27 1.069959 1399.680 184 32 1413120
#> 5 385 2194.50 3050 216 5.70 25 1.055556 2079.000 213 25 2050125
#> 6 302 1887.50 2624 213 6.25 28 1.047954 1801.128 213 28 1801128
# rename added columns to match index of mac1 copy
mac1_copied %>%
map2(
1:num_iterations,
~ .x %>%
rename_with(
function(col_name){str_c(col_name, .y)},
V:X
)
) -> mac1_copied
# view effect
mac1_copied
#> [[1]]
#> Buc MT Kg Lung medie Pcs CTT util V1 W1 X1
#> 1 302 1884.48 2619 213 6.24 28 1.046278 1801.128 216 27 1761264
#> 2 296 1847.40 2568 213 6.24 28 1.046482 1765.344 184 32 1742848
#> 3 304 1869.96 2599 216 6.15 27 1.054730 1772.928 216 27 1772928
#> 4 240 1497.60 2082 216 6.24 27 1.069959 1399.680 184 32 1413120
#> 5 385 2194.50 3050 216 5.70 25 1.055556 2079.000 184 29 2054360
#> 6 302 1887.50 2624 213 6.25 28 1.047954 1801.128 184 32 1778176
#>
#> [[2]]
#> Buc MT Kg Lung medie Pcs CTT util V2 W2 X2
#> 1 302 1884.48 2619 213 6.24 28 1.046278 1801.128 216 27 1761264
#> 2 296 1847.40 2568 213 6.24 28 1.046482 1765.344 184 32 1742848
#> 3 304 1869.96 2599 216 6.15 27 1.054730 1772.928 216 27 1772928
#> 4 240 1497.60 2082 216 6.24 27 1.069959 1399.680 184 32 1413120
#> 5 385 2194.50 3050 216 5.70 25 1.055556 2079.000 213 25 2050125
#> 6 302 1887.50 2624 213 6.25 28 1.047954 1801.128 213 28 1801128
# extract numbered columns from copies and combine into single table
mac1_copied %>%
map_dfc(
~ .x %>% select(matches('[0-9]'))
) -> numbered_columns
# view effect
numbered_columns
#> V1 W1 X1 V2 W2 X2
#> 1 216 27 1761264 216 27 1761264
#> 2 184 32 1742848 184 32 1742848
#> 3 216 27 1772928 216 27 1772928
#> 4 184 32 1413120 184 32 1413120
#> 5 184 29 2054360 213 25 2050125
#> 6 184 32 1778176 213 28 1801128
# add numbered columns to mac1 table
mac1 %>%
cbind(numbered_columns)
#> Buc MT Kg Lung medie Pcs CTT util V1 W1 X1 V2 W2
#> 1 302 1884.48 2619 213 6.24 28 1.046278 1801.128 216 27 1761264 216 27
#> 2 296 1847.40 2568 213 6.24 28 1.046482 1765.344 184 32 1742848 184 32
#> 3 304 1869.96 2599 216 6.15 27 1.054730 1772.928 216 27 1772928 216 27
#> 4 240 1497.60 2082 216 6.24 27 1.069959 1399.680 184 32 1413120 184 32
#> 5 385 2194.50 3050 216 5.70 25 1.055556 2079.000 184 29 2054360 213 25
#> 6 302 1887.50 2624 213 6.25 28 1.047954 1801.128 184 32 1778176 213 28
#> X2
#> 1 1761264
#> 2 1742848
#> 3 1772928
#> 4 1413120
#> 5 2050125
#> 6 1801128
Created on 2024-04-09 with reprex v2.0.2
full reprex
structure(list(Buc = c(302, 296, 304, 240, 385, 302, 322, 306,
357, 295, 320, 315, 218, 270, 280, 360, 288, 294, 308, 283, 302,
209, 312, 210, 314, 305, 195, 279, 229, 294, 310, 173, 306, 308,
238, 268, 227, 200, 339, 198, 94, 309, 198, 308, 294, 192, 294,
318, 268, 268, 208, 240, 313, 316, 318, 314, 297, 340, 340, 340,
340, 326, 295, 320, 340, 340, 67, 99, 135, 64, 126, 318, 316,
315, 314, 316, 316, 300, 308, 316, 313, 306, 191, 190, 195, 318,
199, 316, 316, 312, 314, 306, 316, 316, 310, 315, 316, 288, 314,
316, 314, 269, 315, 314, 302, 307, 316, 313, 288, 339, 354, 70,
280, 316, 304, 303, 299, 247, 305, 315, 322, 114, 308, 303, 309,
294, 325, 200, 198), MT = c(1884.48, 1847.4, 1869.96, 1497.6,
2194.5, 1887.5, 2019, 1915, 2177, 1874, 1952, 1978, 1382, 1385,
1747, 2208, 1805, 1843.38, 1931.16, 1768, 1893.5, 1308.3, 1953,
1331.4, 1978.2, 1930.65, 1234.35, 1766.07, 1454.15, 1902.18,
1984, 1098.55, 1943.1, 1955.8, 1511.3, 1688.4, 1430, 1276, 2148,
1251, 592, 1945, 1260, 1931.16, 1878.66, 1194.24, 1878.66, 2032.02,
1666, 1666, 1144, 1497.6, 1972, 1987, 1996, 1984.5, 1856.25,
2176, 2176, 2176, 2125, 2038, 1843.5, 2000, 2125, 2125, 522,
504, 857, 400, 787.5, 2054.28, 2028.72, 2025.45, 2019.02, 2038.2,
2044.52, 1935, 1989, 2039, 2019, 1964.52, 1230.04, 1229.3, 1251.9,
2060.64, 1287, 2022.4, 2022.4, 1996.8, 2009.6, 1958.4, 2022.4,
2022.4, 1984, 2031, 2038.2, 1857.6, 2025.3, 2047, 2009.6, 1748.5,
2047.5, 2041, 1917.7, 1943.31, 2006.6, 1987.55, 1854.7, 2125.53,
2194.8, 525, 1773.8, 2005.6, 1930.4, 1920, 1894.7, 1568.45, 1933.7,
2000.25, 2044.7, 570, 1925, 1900, 1935, 1885.06, 2040.5, 1274,
1266.6), Kg = c(2619, 2568, 2599, 2082, 3050, 2624, 2806, 2662,
3026, 2605, 2713, 2749, 1921, 1925, 2428, 3069, 2509, 2562, 2684,
2458, 2632, 1819, 2715, 1851, 2750, 2684, 1716, 2455, 2021, 2644,
2758, 1527, 2701, 2719, 2101, 2347, 1988, 1774, 2986, 1739, 823,
2704, 1751, 2684, 2611, 1660, 2611, 2825, 2316, 2316, 1590, 2082,
2741, 2762, 2774, 2758, 2580, 3025, 3025, 3025, 2954, 2833, 2562,
2780, 2954, 2954, 726, 701, 1191, 556, 1095, 2855, 2820, 2815,
2806, 2833, 2842, 2690, 2765, 2834, 2806, 2731, 1710, 1709, 1740,
2864, 1789, 2811, 2811, 2776, 2793, 2722, 2811, 2811, 2758, 2823,
2833, 2582, 2815, 2845, 2793, 2430, 2846, 2837, 2666, 2701, 2789,
2763, 2578, 2954, 3051, 730, 2466, 2788, 2683, 2669, 2634, 2180,
2688, 2780, 2842, 792, 2676, 2641, 2690, 2620, 2836, 1771, 1761
)), row.names = c(NA, -129L), class = "data.frame") -> mac
library(tidyverse)
# verify that data types are numeric
mac %>% as_tibble()
#> # A tibble: 129 × 3
#> Buc MT Kg
#> <dbl> <dbl> <dbl>
#> 1 302 1884. 2619
#> 2 296 1847. 2568
#> 3 304 1870. 2599
#> 4 240 1498. 2082
#> 5 385 2194. 3050
#> 6 302 1888. 2624
#> 7 322 2019 2806
#> 8 306 1915 2662
#> 9 357 2177 3026
#> 10 295 1874 2605
#> # ℹ 119 more rows
# add columns to create mac1 table
mac %>%
mutate(
Lung = sample(x = c(216,213,184), size = 129, replace = TRUE),
medie = round(MT / Buc, 2),
Pcs = floor((medie * 1000 - 200) / Lung),
CTT = MT / (Buc * Lung * Pcs / 1000),
util = (Buc * Lung * Pcs / 1000)
) -> mac1
# view portion of mac1 table
mac1 %>% head()
#> Buc MT Kg Lung medie Pcs CTT util
#> 1 302 1884.48 2619 213 6.24 28 1.046278 1801.128
#> 2 296 1847.40 2568 213 6.24 28 1.046482 1765.344
#> 3 304 1869.96 2599 216 6.15 27 1.054730 1772.928
#> 4 240 1497.60 2082 216 6.24 27 1.069959 1399.680
#> 5 385 2194.50 3050 216 5.70 25 1.055556 2079.000
#> 6 302 1887.50 2624 213 6.25 28 1.047954 1801.128
# this is for viewing purposes in post: remove to use full mac1 table
mac1 <- mac1 %>% head()
# set the number of iterations desired
num_iterations <- 2
# create list with num_iterations copies of mac1
mac1 %>%
list() %>%
rep(num_iterations) -> mac1_copied
# view list
mac1_copied
#> [[1]]
#> Buc MT Kg Lung medie Pcs CTT util
#> 1 302 1884.48 2619 213 6.24 28 1.046278 1801.128
#> 2 296 1847.40 2568 213 6.24 28 1.046482 1765.344
#> 3 304 1869.96 2599 216 6.15 27 1.054730 1772.928
#> 4 240 1497.60 2082 216 6.24 27 1.069959 1399.680
#> 5 385 2194.50 3050 216 5.70 25 1.055556 2079.000
#> 6 302 1887.50 2624 213 6.25 28 1.047954 1801.128
#>
#> [[2]]
#> Buc MT Kg Lung medie Pcs CTT util
#> 1 302 1884.48 2619 213 6.24 28 1.046278 1801.128
#> 2 296 1847.40 2568 213 6.24 28 1.046482 1765.344
#> 3 304 1869.96 2599 216 6.15 27 1.054730 1772.928
#> 4 240 1497.60 2082 216 6.24 27 1.069959 1399.680
#> 5 385 2194.50 3050 216 5.70 25 1.055556 2079.000
#> 6 302 1887.50 2624 213 6.25 28 1.047954 1801.128
# perform parallel computations in each copy of mac1
mac1_copied %>%
map(
~ .x %>%
mutate(
V = sample(x = c(216,213,184), size = nrow(.x), replace = TRUE),
W = floor((medie * 1000 - 200) / V),
X = Buc * V * W)
) -> mac1_copied
# view effect
mac1_copied
#> [[1]]
#> Buc MT Kg Lung medie Pcs CTT util V W X
#> 1 302 1884.48 2619 213 6.24 28 1.046278 1801.128 216 27 1761264
#> 2 296 1847.40 2568 213 6.24 28 1.046482 1765.344 184 32 1742848
#> 3 304 1869.96 2599 216 6.15 27 1.054730 1772.928 216 27 1772928
#> 4 240 1497.60 2082 216 6.24 27 1.069959 1399.680 184 32 1413120
#> 5 385 2194.50 3050 216 5.70 25 1.055556 2079.000 184 29 2054360
#> 6 302 1887.50 2624 213 6.25 28 1.047954 1801.128 184 32 1778176
#>
#> [[2]]
#> Buc MT Kg Lung medie Pcs CTT util V W X
#> 1 302 1884.48 2619 213 6.24 28 1.046278 1801.128 216 27 1761264
#> 2 296 1847.40 2568 213 6.24 28 1.046482 1765.344 184 32 1742848
#> 3 304 1869.96 2599 216 6.15 27 1.054730 1772.928 216 27 1772928
#> 4 240 1497.60 2082 216 6.24 27 1.069959 1399.680 184 32 1413120
#> 5 385 2194.50 3050 216 5.70 25 1.055556 2079.000 213 25 2050125
#> 6 302 1887.50 2624 213 6.25 28 1.047954 1801.128 213 28 1801128
# rename added columns to match index of mac1 copy
mac1_copied %>%
map2(
1:num_iterations,
~ .x %>%
rename_with(
function(col_name){str_c(col_name, .y)},
V:X
)
) -> mac1_copied
# view effect
mac1_copied
#> [[1]]
#> Buc MT Kg Lung medie Pcs CTT util V1 W1 X1
#> 1 302 1884.48 2619 213 6.24 28 1.046278 1801.128 216 27 1761264
#> 2 296 1847.40 2568 213 6.24 28 1.046482 1765.344 184 32 1742848
#> 3 304 1869.96 2599 216 6.15 27 1.054730 1772.928 216 27 1772928
#> 4 240 1497.60 2082 216 6.24 27 1.069959 1399.680 184 32 1413120
#> 5 385 2194.50 3050 216 5.70 25 1.055556 2079.000 184 29 2054360
#> 6 302 1887.50 2624 213 6.25 28 1.047954 1801.128 184 32 1778176
#>
#> [[2]]
#> Buc MT Kg Lung medie Pcs CTT util V2 W2 X2
#> 1 302 1884.48 2619 213 6.24 28 1.046278 1801.128 216 27 1761264
#> 2 296 1847.40 2568 213 6.24 28 1.046482 1765.344 184 32 1742848
#> 3 304 1869.96 2599 216 6.15 27 1.054730 1772.928 216 27 1772928
#> 4 240 1497.60 2082 216 6.24 27 1.069959 1399.680 184 32 1413120
#> 5 385 2194.50 3050 216 5.70 25 1.055556 2079.000 213 25 2050125
#> 6 302 1887.50 2624 213 6.25 28 1.047954 1801.128 213 28 1801128
# extract numbered columns from copies and combine into single table
mac1_copied %>%
map_dfc(
~ .x %>% select(matches('[0-9]'))
) -> numbered_columns
# view effect
numbered_columns
#> V1 W1 X1 V2 W2 X2
#> 1 216 27 1761264 216 27 1761264
#> 2 184 32 1742848 184 32 1742848
#> 3 216 27 1772928 216 27 1772928
#> 4 184 32 1413120 184 32 1413120
#> 5 184 29 2054360 213 25 2050125
#> 6 184 32 1778176 213 28 1801128
# add numbered columns to mac1 table
mac1 %>%
cbind(numbered_columns)
#> Buc MT Kg Lung medie Pcs CTT util V1 W1 X1 V2 W2
#> 1 302 1884.48 2619 213 6.24 28 1.046278 1801.128 216 27 1761264 216 27
#> 2 296 1847.40 2568 213 6.24 28 1.046482 1765.344 184 32 1742848 184 32
#> 3 304 1869.96 2599 216 6.15 27 1.054730 1772.928 216 27 1772928 216 27
#> 4 240 1497.60 2082 216 6.24 27 1.069959 1399.680 184 32 1413120 184 32
#> 5 385 2194.50 3050 216 5.70 25 1.055556 2079.000 184 29 2054360 213 25
#> 6 302 1887.50 2624 213 6.25 28 1.047954 1801.128 184 32 1778176 213 28
#> X2
#> 1 1761264
#> 2 1742848
#> 3 1772928
#> 4 1413120
#> 5 2050125
#> 6 1801128
Created on 2024-04-09 with reprex v2.0.2
And here's an alternative approach more in line with the tidyverse, with full, easy-to-copy reprex at bottom of post.
code to build mac1 table
structure(list(Buc = c(302, 296, 304, 240, 385, 302, 322, 306,
357, 295, 320, 315, 218, 270, 280, 360, 288, 294, 308, 283, 302,
209, 312, 210, 314, 305, 195, 279, 229, 294, 310, 173, 306, 308,
238, 268, 227, 200, 339, 198, 94, 309, 198, 308, 294, 192, 294,
318, 268, 268, 208, 240, 313, 316, 318, 314, 297, 340, 340, 340,
340, 326, 295, 320, 340, 340, 67, 99, 135, 64, 126, 318, 316,
315, 314, 316, 316, 300, 308, 316, 313, 306, 191, 190, 195, 318,
199, 316, 316, 312, 314, 306, 316, 316, 310, 315, 316, 288, 314,
316, 314, 269, 315, 314, 302, 307, 316, 313, 288, 339, 354, 70,
280, 316, 304, 303, 299, 247, 305, 315, 322, 114, 308, 303, 309,
294, 325, 200, 198), MT = c(1884.48, 1847.4, 1869.96, 1497.6,
2194.5, 1887.5, 2019, 1915, 2177, 1874, 1952, 1978, 1382, 1385,
1747, 2208, 1805, 1843.38, 1931.16, 1768, 1893.5, 1308.3, 1953,
1331.4, 1978.2, 1930.65, 1234.35, 1766.07, 1454.15, 1902.18,
1984, 1098.55, 1943.1, 1955.8, 1511.3, 1688.4, 1430, 1276, 2148,
1251, 592, 1945, 1260, 1931.16, 1878.66, 1194.24, 1878.66, 2032.02,
1666, 1666, 1144, 1497.6, 1972, 1987, 1996, 1984.5, 1856.25,
2176, 2176, 2176, 2125, 2038, 1843.5, 2000, 2125, 2125, 522,
504, 857, 400, 787.5, 2054.28, 2028.72, 2025.45, 2019.02, 2038.2,
2044.52, 1935, 1989, 2039, 2019, 1964.52, 1230.04, 1229.3, 1251.9,
2060.64, 1287, 2022.4, 2022.4, 1996.8, 2009.6, 1958.4, 2022.4,
2022.4, 1984, 2031, 2038.2, 1857.6, 2025.3, 2047, 2009.6, 1748.5,
2047.5, 2041, 1917.7, 1943.31, 2006.6, 1987.55, 1854.7, 2125.53,
2194.8, 525, 1773.8, 2005.6, 1930.4, 1920, 1894.7, 1568.45, 1933.7,
2000.25, 2044.7, 570, 1925, 1900, 1935, 1885.06, 2040.5, 1274,
1266.6), Kg = c(2619, 2568, 2599, 2082, 3050, 2624, 2806, 2662,
3026, 2605, 2713, 2749, 1921, 1925, 2428, 3069, 2509, 2562, 2684,
2458, 2632, 1819, 2715, 1851, 2750, 2684, 1716, 2455, 2021, 2644,
2758, 1527, 2701, 2719, 2101, 2347, 1988, 1774, 2986, 1739, 823,
2704, 1751, 2684, 2611, 1660, 2611, 2825, 2316, 2316, 1590, 2082,
2741, 2762, 2774, 2758, 2580, 3025, 3025, 3025, 2954, 2833, 2562,
2780, 2954, 2954, 726, 701, 1191, 556, 1095, 2855, 2820, 2815,
2806, 2833, 2842, 2690, 2765, 2834, 2806, 2731, 1710, 1709, 1740,
2864, 1789, 2811, 2811, 2776, 2793, 2722, 2811, 2811, 2758, 2823,
2833, 2582, 2815, 2845, 2793, 2430, 2846, 2837, 2666, 2701, 2789,
2763, 2578, 2954, 3051, 730, 2466, 2788, 2683, 2669, 2634, 2180,
2688, 2780, 2842, 792, 2676, 2641, 2690, 2620, 2836, 1771, 1761
)), row.names = c(NA, -129L), class = "data.frame") -> mac
library(tidyverse)
# verify that data types are numeric
mac %>% as_tibble()
#> # A tibble: 129 × 3
#> Buc MT Kg
#> <dbl> <dbl> <dbl>
#> 1 302 1884. 2619
#> 2 296 1847. 2568
#> 3 304 1870. 2599
#> 4 240 1498. 2082
#> 5 385 2194. 3050
#> 6 302 1888. 2624
#> 7 322 2019 2806
#> 8 306 1915 2662
#> 9 357 2177 3026
#> 10 295 1874 2605
#> # ℹ 119 more rows
# add columns to create mac1 table
mac %>%
mutate(
Lung = sample(x = c(216,213,184), size = 129, replace = TRUE),
medie = round(MT / Buc, 2),
Pcs = floor((medie * 1000 - 200) / Lung),
CTT = MT / (Buc * Lung * Pcs / 1000),
util = (Buc * Lung * Pcs / 1000)
) -> mac1
# this is for viewing purposes in post: remove to use full mac1 table
mac1 <- mac1 %>% head()
# view portion of mac1 table
mac1 %>% head()
#> Buc MT Kg Lung medie Pcs CTT util
#> 1 302 1884.48 2619 184 6.24 32 1.059783 1778.176
#> 2 296 1847.40 2568 216 6.24 27 1.070167 1726.272
#> 3 304 1869.96 2599 184 6.15 32 1.044698 1789.952
#> 4 240 1497.60 2082 216 6.24 27 1.069959 1399.680
#> 5 385 2194.50 3050 213 5.70 25 1.070423 2050.125
#> 6 302 1887.50 2624 213 6.25 28 1.047954 1801.128
# set the number of iterations desired
num_iterations <- 2
# create long version of mac1 with iterations
1:num_iterations %>%
map_dfr(
~ mac1 %>% mutate(iteration = .x)
) -> mac1_long
# view result
mac1_long
#> Buc MT Kg Lung medie Pcs CTT util iteration
#> 1 302 1884.48 2619 216 6.24 27 1.069959 1761.264 1
#> 2 296 1847.40 2568 184 6.24 32 1.059989 1742.848 1
#> 3 304 1869.96 2599 213 6.15 27 1.069585 1748.304 1
#> 4 240 1497.60 2082 184 6.24 32 1.059783 1413.120 1
#> 5 385 2194.50 3050 213 5.70 25 1.070423 2050.125 1
#> 6 302 1887.50 2624 184 6.25 32 1.061481 1778.176 1
#> 7 302 1884.48 2619 216 6.24 27 1.069959 1761.264 2
#> 8 296 1847.40 2568 184 6.24 32 1.059989 1742.848 2
#> 9 304 1869.96 2599 213 6.15 27 1.069585 1748.304 2
#> 10 240 1497.60 2082 184 6.24 32 1.059783 1413.120 2
#> 11 385 2194.50 3050 213 5.70 25 1.070423 2050.125 2
#> 12 302 1887.50 2624 184 6.25 32 1.061481 1778.176 2
# perform parallel computations in each subtable of mac1_long
mac1_long %>%
group_by(iteration) %>%
mutate(
V = sample(x = c(216,213,184), size = n(), replace = TRUE),
W = floor((medie * 1000 - 200) / V),
X = Buc * V * W
) %>%
ungroup() -> mac1_long
# view result, which would be final if tidy(verse) version is desired
mac1_long
#> # A tibble: 12 × 12
#> Buc MT Kg Lung medie Pcs CTT util iteration V W X
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
#> 1 302 1884. 2619 216 6.24 27 1.07 1761. 1 184 32 1778176
#> 2 296 1847. 2568 184 6.24 32 1.06 1743. 1 184 32 1742848
#> 3 304 1870. 2599 213 6.15 27 1.07 1748. 1 216 27 1772928
#> 4 240 1498. 2082 184 6.24 32 1.06 1413. 1 184 32 1413120
#> 5 385 2194. 3050 213 5.7 25 1.07 2050. 1 213 25 2050125
#> 6 302 1888. 2624 184 6.25 32 1.06 1778. 1 184 32 1778176
#> 7 302 1884. 2619 216 6.24 27 1.07 1761. 2 213 28 1801128
#> 8 296 1847. 2568 184 6.24 32 1.06 1743. 2 213 28 1765344
#> 9 304 1870. 2599 213 6.15 27 1.07 1748. 2 216 27 1772928
#> 10 240 1498. 2082 184 6.24 32 1.06 1413. 2 216 27 1399680
#> 11 385 2194. 3050 213 5.7 25 1.07 2050. 2 213 25 2050125
#> 12 302 1888. 2624 184 6.25 32 1.06 1778. 2 213 28 1801128
# reformat to produce numbered columns, if Excel-like result is desired
mac1_long %>%
pivot_wider(
names_from = iteration,
values_from = V:X,
names_glue = '{.value}{iteration}')
#> # A tibble: 6 × 14
#> Buc MT Kg Lung medie Pcs CTT util V1 V2 W1 W2 X1
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 302 1884. 2619 216 6.24 27 1.07 1761. 184 213 32 28 1.78e6
#> 2 296 1847. 2568 184 6.24 32 1.06 1743. 184 213 32 28 1.74e6
#> 3 304 1870. 2599 213 6.15 27 1.07 1748. 216 216 27 27 1.77e6
#> 4 240 1498. 2082 184 6.24 32 1.06 1413. 184 216 32 27 1.41e6
#> 5 385 2194. 3050 213 5.7 25 1.07 2050. 213 213 25 25 2.05e6
#> 6 302 1888. 2624 184 6.25 32 1.06 1778. 184 213 32 28 1.78e6
#> # ℹ 1 more variable: X2 <dbl>
Created on 2024-04-09 with reprex v2.0.2
full reprex
structure(list(Buc = c(302, 296, 304, 240, 385, 302, 322, 306,
357, 295, 320, 315, 218, 270, 280, 360, 288, 294, 308, 283, 302,
209, 312, 210, 314, 305, 195, 279, 229, 294, 310, 173, 306, 308,
238, 268, 227, 200, 339, 198, 94, 309, 198, 308, 294, 192, 294,
318, 268, 268, 208, 240, 313, 316, 318, 314, 297, 340, 340, 340,
340, 326, 295, 320, 340, 340, 67, 99, 135, 64, 126, 318, 316,
315, 314, 316, 316, 300, 308, 316, 313, 306, 191, 190, 195, 318,
199, 316, 316, 312, 314, 306, 316, 316, 310, 315, 316, 288, 314,
316, 314, 269, 315, 314, 302, 307, 316, 313, 288, 339, 354, 70,
280, 316, 304, 303, 299, 247, 305, 315, 322, 114, 308, 303, 309,
294, 325, 200, 198), MT = c(1884.48, 1847.4, 1869.96, 1497.6,
2194.5, 1887.5, 2019, 1915, 2177, 1874, 1952, 1978, 1382, 1385,
1747, 2208, 1805, 1843.38, 1931.16, 1768, 1893.5, 1308.3, 1953,
1331.4, 1978.2, 1930.65, 1234.35, 1766.07, 1454.15, 1902.18,
1984, 1098.55, 1943.1, 1955.8, 1511.3, 1688.4, 1430, 1276, 2148,
1251, 592, 1945, 1260, 1931.16, 1878.66, 1194.24, 1878.66, 2032.02,
1666, 1666, 1144, 1497.6, 1972, 1987, 1996, 1984.5, 1856.25,
2176, 2176, 2176, 2125, 2038, 1843.5, 2000, 2125, 2125, 522,
504, 857, 400, 787.5, 2054.28, 2028.72, 2025.45, 2019.02, 2038.2,
2044.52, 1935, 1989, 2039, 2019, 1964.52, 1230.04, 1229.3, 1251.9,
2060.64, 1287, 2022.4, 2022.4, 1996.8, 2009.6, 1958.4, 2022.4,
2022.4, 1984, 2031, 2038.2, 1857.6, 2025.3, 2047, 2009.6, 1748.5,
2047.5, 2041, 1917.7, 1943.31, 2006.6, 1987.55, 1854.7, 2125.53,
2194.8, 525, 1773.8, 2005.6, 1930.4, 1920, 1894.7, 1568.45, 1933.7,
2000.25, 2044.7, 570, 1925, 1900, 1935, 1885.06, 2040.5, 1274,
1266.6), Kg = c(2619, 2568, 2599, 2082, 3050, 2624, 2806, 2662,
3026, 2605, 2713, 2749, 1921, 1925, 2428, 3069, 2509, 2562, 2684,
2458, 2632, 1819, 2715, 1851, 2750, 2684, 1716, 2455, 2021, 2644,
2758, 1527, 2701, 2719, 2101, 2347, 1988, 1774, 2986, 1739, 823,
2704, 1751, 2684, 2611, 1660, 2611, 2825, 2316, 2316, 1590, 2082,
2741, 2762, 2774, 2758, 2580, 3025, 3025, 3025, 2954, 2833, 2562,
2780, 2954, 2954, 726, 701, 1191, 556, 1095, 2855, 2820, 2815,
2806, 2833, 2842, 2690, 2765, 2834, 2806, 2731, 1710, 1709, 1740,
2864, 1789, 2811, 2811, 2776, 2793, 2722, 2811, 2811, 2758, 2823,
2833, 2582, 2815, 2845, 2793, 2430, 2846, 2837, 2666, 2701, 2789,
2763, 2578, 2954, 3051, 730, 2466, 2788, 2683, 2669, 2634, 2180,
2688, 2780, 2842, 792, 2676, 2641, 2690, 2620, 2836, 1771, 1761
)), row.names = c(NA, -129L), class = "data.frame") -> mac
library(tidyverse)
# verify that data types are numeric
mac %>% as_tibble()
#> # A tibble: 129 × 3
#> Buc MT Kg
#> <dbl> <dbl> <dbl>
#> 1 302 1884. 2619
#> 2 296 1847. 2568
#> 3 304 1870. 2599
#> 4 240 1498. 2082
#> 5 385 2194. 3050
#> 6 302 1888. 2624
#> 7 322 2019 2806
#> 8 306 1915 2662
#> 9 357 2177 3026
#> 10 295 1874 2605
#> # ℹ 119 more rows
# add columns to create mac1 table
mac %>%
mutate(
Lung = sample(x = c(216,213,184), size = 129, replace = TRUE),
medie = round(MT / Buc, 2),
Pcs = floor((medie * 1000 - 200) / Lung),
CTT = MT / (Buc * Lung * Pcs / 1000),
util = (Buc * Lung * Pcs / 1000)
) -> mac1
# view portion of data
mac1 %>% head()
#> Buc MT Kg Lung medie Pcs CTT util
#> 1 302 1884.48 2619 216 6.24 27 1.069959 1761.264
#> 2 296 1847.40 2568 184 6.24 32 1.059989 1742.848
#> 3 304 1869.96 2599 213 6.15 27 1.069585 1748.304
#> 4 240 1497.60 2082 184 6.24 32 1.059783 1413.120
#> 5 385 2194.50 3050 213 5.70 25 1.070423 2050.125
#> 6 302 1887.50 2624 184 6.25 32 1.061481 1778.176
# this is for viewing purposes in post: remove to use full mac1 table
mac1 <- mac1 %>% head()
# set the number of iterations desired
num_iterations <- 2
# create long version of mac1 with iterations
1:num_iterations %>%
map_dfr(
~ mac1 %>% mutate(iteration = .x)
) -> mac1_long
# view result
mac1_long
#> Buc MT Kg Lung medie Pcs CTT util iteration
#> 1 302 1884.48 2619 216 6.24 27 1.069959 1761.264 1
#> 2 296 1847.40 2568 184 6.24 32 1.059989 1742.848 1
#> 3 304 1869.96 2599 213 6.15 27 1.069585 1748.304 1
#> 4 240 1497.60 2082 184 6.24 32 1.059783 1413.120 1
#> 5 385 2194.50 3050 213 5.70 25 1.070423 2050.125 1
#> 6 302 1887.50 2624 184 6.25 32 1.061481 1778.176 1
#> 7 302 1884.48 2619 216 6.24 27 1.069959 1761.264 2
#> 8 296 1847.40 2568 184 6.24 32 1.059989 1742.848 2
#> 9 304 1869.96 2599 213 6.15 27 1.069585 1748.304 2
#> 10 240 1497.60 2082 184 6.24 32 1.059783 1413.120 2
#> 11 385 2194.50 3050 213 5.70 25 1.070423 2050.125 2
#> 12 302 1887.50 2624 184 6.25 32 1.061481 1778.176 2
# perform parallel computations in each subtable of mac1_long
mac1_long %>%
group_by(iteration) %>%
mutate(
V = sample(x = c(216,213,184), size = n(), replace = TRUE),
W = floor((medie * 1000 - 200) / V),
X = Buc * V * W
) %>%
ungroup() -> mac1_long
# view result, which would be final if tidy(verse) version is desired
mac1_long
#> # A tibble: 12 × 12
#> Buc MT Kg Lung medie Pcs CTT util iteration V W X
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
#> 1 302 1884. 2619 216 6.24 27 1.07 1761. 1 184 32 1778176
#> 2 296 1847. 2568 184 6.24 32 1.06 1743. 1 184 32 1742848
#> 3 304 1870. 2599 213 6.15 27 1.07 1748. 1 216 27 1772928
#> 4 240 1498. 2082 184 6.24 32 1.06 1413. 1 184 32 1413120
#> 5 385 2194. 3050 213 5.7 25 1.07 2050. 1 213 25 2050125
#> 6 302 1888. 2624 184 6.25 32 1.06 1778. 1 184 32 1778176
#> 7 302 1884. 2619 216 6.24 27 1.07 1761. 2 213 28 1801128
#> 8 296 1847. 2568 184 6.24 32 1.06 1743. 2 213 28 1765344
#> 9 304 1870. 2599 213 6.15 27 1.07 1748. 2 216 27 1772928
#> 10 240 1498. 2082 184 6.24 32 1.06 1413. 2 216 27 1399680
#> 11 385 2194. 3050 213 5.7 25 1.07 2050. 2 213 25 2050125
#> 12 302 1888. 2624 184 6.25 32 1.06 1778. 2 213 28 1801128
# reformat to produce numbered columns, if Excel-like result is desired
mac1_long %>%
pivot_wider(
names_from = iteration,
values_from = V:X,
names_glue = '{.value}{iteration}')
#> # A tibble: 6 × 14
#> Buc MT Kg Lung medie Pcs CTT util V1 V2 W1 W2 X1
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 302 1884. 2619 216 6.24 27 1.07 1761. 184 213 32 28 1.78e6
#> 2 296 1847. 2568 184 6.24 32 1.06 1743. 184 213 32 28 1.74e6
#> 3 304 1870. 2599 213 6.15 27 1.07 1748. 216 216 27 27 1.77e6
#> 4 240 1498. 2082 184 6.24 32 1.06 1413. 184 216 32 27 1.41e6
#> 5 385 2194. 3050 213 5.7 25 1.07 2050. 213 213 25 25 2.05e6
#> 6 302 1888. 2624 184 6.25 32 1.06 1778. 184 213 32 28 1.78e6
#> # ℹ 1 more variable: X2 <dbl>
Created on 2024-04-09 with reprex v2.0.2
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.