Iteration all variables with quantiles of one changeable variable (ntile)

Hi. This is a post I have been repeating during time, but the struggle to get it done with iterative method with syntax is hard. I don't really know where people solving it get information about it
Here it goes!

structure(list(paciente = c(6341, 6374, 6451, 6414, 6208, 6152, 
6292), peso1_v00 = c(95, 71.6, 68, 88, 72.7, 92.5, 95.9), cintura1_v00 = c(114, 
104, 99, 103, 103.5, 116, 104.5), tasis2_e_v00 = c(115, 123, 
122, 131, 146, 152, 132), tadias2_e_v00 = c(81, 91, 56, 65, 84, 
73, 74), p17_total_v00 = c(9, 9, 11, 5, 6, 7, 4), geaf_tot_v00 = c(2769.23, 
2517.48, 9860.14, 1538.46, 2601.4, 279.72, 5594.41), glucosa_v00 = c(99, 
131, 111, 134, 126, 110, 107), albumi_v00 = c(4.85, 4.13, 4.56, 
4.48, 4.59, 4.64, 4.53), coltot_v00 = c(200, 273, 189, 179, 177, 
311, 241), hdl_v00 = c(48, 59, 43, 38, 63, 59, 46), ldl_calc_v00 = c(121, 
190, 118, 112, 96, 232, 170), trigli_v00 = c(157, 118, 139, 143, 
90, 100, 125), hba1c_v00 = c(5.8, 7.02, 5.75, 6.47, 6.37, 6.24, 
6.16), peso1_v66 = c(90, 67.2, 60.4, 77.5, 71.5, 86.5, 93.9), 
    cintura1_v66 = c(109, 100, 93, 99, 103.5, 110.5, 102), tasis2_e_v66 = c(129, 
    142, 106, 128, 146, 139, 130), tadias2_e_v66 = c(92, 73, 
    45, 63, 80, 73, 62), p17_total_v66 = c(7, 14, 12, 11, 10, 
    11, 10), geaf_tot_v66 = c(852.21, 2377.62, 5146.85, 1000, 
    5384.62, 1258.74, 2797.2), glucosa_v66 = c(88, 136, 96, 101, 
    131, 109, 99), albumi_v66 = c(4.62, 4.05, 4.71, 4.82, 4.7, 
    4.7, 4.35), coltot_v66 = c(222, 242, 183, 168, 189, 183, 
    220), hdl_v66 = c(49, 65, 51, 43, 72, 54, 41), ldl_calc_v66 = c(145, 
    159, 111, 104, 99, 111, 151), trigli_v66 = c(138, 91, 103, 
    103, 89, 90, 142), hba1c_v66 = c(5.78, 7.48, 5.65, 5.69, 
    6.27, 5.68, 6.01), peso1_v01 = c(88.5, 65, 60, 77.2, 73.2, 
    83.5, 92), cintura1_v01 = c(107.2, 99, 92.5, 99.5, 104.5, 
    108.5, 100), tasis2_e_v01 = c(107, 138, 121, 140, 145, 138, 
    132), tadias2_e_v01 = c(76, 80, 55, 73, 79, 61, 74), p17_total_v01 = c(8, 
    12, 16, 10, 9, 10, 9), geaf_tot_v01 = c(1835.2, 629.37, 12167.83, 
    2629.37, 2958.04, 3104.9, 4391.61), glucosa_v01 = c(96, 134, 
    102, 126, 130, 109, 104), albumi_v01 = c(4.71, 4.33, 4.82, 
    4.48, 4.72, 4.84, 4.64), coltot_v01 = c(237, 298, 220, 178, 
    186, 231, 218), hdl_v01 = c(55, 67, 48, 44, 71, 53, 52), 
    ldl_calc_v01 = c(149, 202, 137, 112, 99, 157, 148), trigli_v01 = c(166, 
    143, 173, 110, 81, 105, 89), hba1c_v01 = c(5.69, 7.46, 5.61, 
    5.77, 6.69, 6.13, 5.9), i_hucpeptide_v00 = c(534.12, 660.9, 
    920.75, 1466.98, 949.33, 923.8, 1159.06), i_hucpeptide_v66 = c(1049.74, 
    542.49, 523.9, 836.45, 815.06, 904.6, 840.42), i_hucpeptide_v01 = c(637.64, 
    572.08, 710.62, 1191.65, 719.71, 1097.25, 819.63), i_hughrelin_v00 = c(1655.94, 
    341.76, 410.11, 403.59, 404.93, 587.99, 668.4), i_hughrelin_v66 = c(2408.85, 
    337.06, 525.66, 465.85, 418.8, 548.46, 778.84), i_hughrelin_v01 = c(1943.83, 
    378.8, 425.4, 487.19, 372.88, 657.97, 627.83), i_hugip_v00 = c(2.67, 
    2.67, 2.67, 2.67, 2.67, 2.67, 2.67), i_hugip_v66 = c(2.67, 
    2.67, 2.67, 2.67, 2.67, 2.67, 2.67), i_hugip_v01 = c(2.67, 
    2.67, 2.67, 2.67, 2.67, 2.67, 2.67), i_huglp1_v00 = c(14.14, 
    263.16, 14.14, 139.66, 71.6, 111.97, 242.83), i_huglp1_v66 = c(168.68, 
    287.4, 14.14, 14.14, 48.31, 14.14, 89.91), i_huglp1_v01 = c(70.59, 
    216.2, 14.14, 14.14, 14.14, 14.14, 46.94), i_huglucagon_v00 = c(335.55, 
    364.74, 427.58, 360.87, 208.59, 342.57, 425.75), i_huglucagon_v66 = c(390.38, 
    381.64, 218.96, 205.08, 200.7, 257.12, 336.04), i_huglucagon_v01 = c(299.75, 
    351.01, 429.22, 336.68, 237.79, 240.47, 322.02), i_huinsulin_v00 = c(113.87, 
    172.83, 234.31, 496.76, 244.37, 198.79, 301.1), i_huinsulin_v66 = c(180.47, 
    136.82, 112.03, 199.44, 245.46, 207.41, 196.36), i_huinsulin_v01 = c(146.93, 
    132.32, 223.56, 378.67, 178.28, 240.56, 211.35), i_huleptin_v00 = c(2089.65, 
    4700.59, 9539.79, 7335.23, 3810.87, 1811.93, 4220.27), i_huleptin_v66 = c(3237.6, 
    5858.84, 4035.94, 2798.57, 3304.25, 771.28, 1876.25), i_huleptin_v01 = c(2086.63, 
    4711.17, 7653.18, 6050.05, 3729.85, 676.33, 2309.12), i_hupai1_v00 = c(1897.07, 
    1580.06, 2156.52, 3865.56, 1900.63, 4015.04, 3624.81), i_hupai1_v66 = c(2136.71, 
    1763.56, 852.71, 2459.03, 1632.91, 2159.92, 2057.15), i_hupai1_v01 = c(2242.9, 
    1846.05, 1657.87, 3634.8, 1675.73, 2526.22, 2216.94), i_huresistin_v00 = c(2389.2, 
    5361.99, 2804.64, 5206.78, 5272.32, 2928.88, 3489.5), i_huresistin_v66 = c(4570.75, 
    5712.39, 2696.17, 6505.27, 3853.94, 2976.32, 2796.81), i_huresistin_v01 = c(2781.07, 
    6171.67, 2531.58, 5598.15, 3387.95, 3195.83, 2509.48), i_huvisfatin_v00 = c(8.64, 
    725.34, 1720.74, 572.56, 204.21, 158.65, 591.11), i_huvisfatin_v66 = c(8.64, 
    901.09, 190.56, 8.64, 6.43, 8.64, 8.64), i_huvisfatin_v01 = c(8.64, 
    421.86, 1321.23, 412.23, 143.79, 8.64, 7.83), col_rema_v00 = c(31, 
    24, 28, 29, 18, 20, 25), col_rema_v66 = c(28, 18, 21, 21, 
    18, 18, 28), col_rema_v01 = c(33, 29, 35, 22, 16, 21, 18), 
    homa_v00 = c(501.028, 1006.25466666667, 1155.92933333333, 
    2958.48177777778, 1368.472, 971.862222222222, 1431.89777777778
    ), homa_v66 = c(705.838222222222, 827.000888888889, 477.994666666667, 
    895.264, 1429.12266666667, 1004.78622222222, 863.984), homa_v01 = c(626.901333333333, 
    788.039111111111, 1013.472, 2120.552, 1030.06222222222, 1165.37955555556, 
    976.906666666667), d_homa_v66 = c(204.810222222222, -179.253777777778, 
    -677.934666666667, -2063.21777777778, 60.6506666666667, 32.924, 
    -567.913777777778), d_homa_v01 = c(125.873333333333, -218.215555555556, 
    -142.457333333333, -837.929777777777, -338.409777777778, 
    193.517333333333, -454.991111111111), d_hughrelin_v66 = c(752.91, 
    -4.69999999999999, 115.55, 62.26, 13.87, -39.53, 110.44), 
    d_hughrelin_v01 = c(287.89, 37.04, 15.29, 83.6, -32.05, 69.98, 
    -40.5699999999999), d_huinsulin_v66 = c(66.6, -36.01, -122.28, 
    -297.32, 1.09, 8.62, -104.74), d_huinsulin_v01 = c(33.06, 
    -40.51, -10.75, -118.09, -66.09, 41.77, -89.75), d_hucpeptide_v66 = c(515.62, 
    -118.41, -396.85, -630.53, -134.27, -19.1999999999999, -318.64
    ), d_hucpeptide_v01 = c(103.52, -88.8199999999999, -210.13, 
    -275.33, -229.62, 173.45, -339.43), d_huglucagon_v66 = c(54.83, 
    16.9, -208.62, -155.79, -7.89000000000001, -85.45, -89.71
    ), d_huglucagon_v01 = c(-35.8, -13.73, 1.64000000000004, 
    -24.19, 29.2, -102.1, -103.73), d_huleptin_v66 = c(1147.95, 
    1158.25, -5503.85, -4536.66, -506.62, -1040.65, -2344.02), 
    d_huleptin_v01 = c(-3.01999999999998, 10.5799999999999, -1886.61, 
    -1285.18, -81.02, -1135.6, -1911.15), d_huresistin_v66 = c(2181.55, 
    350.400000000001, -108.47, 1298.49, -1418.38, 47.4400000000001, 
    -692.69), d_huresistin_v01 = c(391.87, 809.68, -273.06, 391.37, 
    -1884.37, 266.95, -980.02), d_huvisfatin_v66 = c(0, 175.75, 
    -1530.18, -563.92, -197.78, -150.01, -582.47), d_huvisfatin_v01 = c(0, 
    -303.48, -399.51, -160.33, -60.42, -150.01, -583.28), d_glucosa_v66 = c(-11, 
    5, -15, -33, 5, -1, -8), d_glucosa_v01 = c(-3, 3, -9, -8, 
    4, -1, -3), d_coltot_v66 = c(22, -31, -6, -11, 12, -128, 
    -21), d_coltot_v01 = c(37, 25, 31, -1, 9, -80, -23), d_hdl_v66 = c(1, 
    6, 8, 5, 9, -5, -5), d_hdl_v01 = c(7, 8, 5, 6, 8, -6, 6), 
    d_ldl_calc_v66 = c(24, -31, -7, -8, 3, -121, -19), d_ldl_calc_v01 = c(28, 
    12, 19, 0, 3, -75, -22), d_col_rema_v66 = c(-3, -6, -7, -8, 
    0, -2, 3), d_col_rema_v01 = c(2, 5, 7, -7, -2, 1, -7), d_trigli_v66 = c(-19, 
    -27, -36, -40, -1, -10, 17), d_trigli_v01 = c(9, 25, 34, 
    -33, -9, 5, -36), d_hba1c_v66 = c(-0.0199999999999996, 0.460000000000001, 
    -0.0999999999999996, -0.779999999999999, -0.100000000000001, 
    -0.56, -0.15), d_hba1c_v01 = c(-0.109999999999999, 0.44, 
    -0.14, -0.7, 0.32, -0.11, -0.26), d_tasis2_e_v66 = c(14, 
    19, -16, -3, 0, -13, -2), d_tasis2_e_v01 = c(-8, 15, -1, 
    9, -1, -14, 0), d_tadias2_e_v66 = c(11, -18, -11, -2, -4, 
    0, -12), d_tadias2_e_v01 = c(-5, -11, -1, 8, -5, -12, 0), 
    d_peso1_v66 = c(-5, -4.39999999999999, -7.6, -10.5, -1.2, 
    -6, -2), d_peso1_v01 = c(-6.5, -6.59999999999999, -8, -10.8, 
    0.5, -9, -3.90000000000001), d_cintura1_v66 = c(-5, -4, -6, 
    -4, 0, -5.5, -2.5), d_cintura1_v01 = c(-6.8, -5, -6.5, -3.5, 
    1, -7.5, -4.5), d_geaf_tot_v66 = c(-1917.02, -139.86, -4713.29, 
    -538.46, 2783.22, 979.02, -2797.21), d_geaf_tot_v01 = c(-934.03, 
    -1888.11, 2307.69, 1090.91, 356.64, 2825.18, -1202.8), d_p17_total_v66 = c(-2, 
    5, 1, 6, 4, 4, 6), d_p17_total_v01 = c(-1, 3, 5, 5, 3, 3, 
    5), d_hupai1_v66 = c(239.64, 183.5, -1303.81, -1406.53, -267.72, 
    -1855.12, -1567.66), d_hupai1_v01 = c(345.83, 265.99, -498.65, 
    -230.76, -224.9, -1488.82, -1407.87), d_hugip_v66 = c(0, 
    0, 0, 0, 0, 0, 0), d_hugip_v01 = c(0, 0, 0, 0, 0, 0, 0), 
    d_huglp1_v66 = c(154.54, 24.24, 0, -125.52, -23.29, -97.83, 
    -152.92), d_huglp1_v01 = c(56.45, -46.96, 0, -125.52, -57.46, 
    -97.83, -195.89), ln_trigli_v00 = c(5.05624580534831, 4.77068462446567, 
    4.93447393313069, 4.96284463025991, 4.49980967033027, 4.60517018598809, 
    4.8283137373023), ln_trigli_v66 = c(4.92725368515721, 4.51085950651685, 
    4.63472898822964, 4.63472898822964, 4.48863636973214, 4.49980967033027, 
    4.95582705760126), ln_trigli_v01 = c(5.11198778835654, 4.96284463025991, 
    5.15329159449778, 4.70048036579242, 4.39444915467244, 4.65396035015752, 
    4.48863636973214), ln_homa_v00 = c(6.21666198774673, 6.91399046640318, 
    7.0526599170293, 7.99243150282037, 7.22145006791336, 6.87921404772847, 
    7.26675596073922), ln_homa_v66 = c(6.55938606424104, 6.71780576985853, 
    6.16959957482809, 6.79711864684619, 7.26481601516014, 6.91253008365956, 
    6.76155425011407), ln_homa_v01 = c(6.44078916514532, 6.66954772201592, 
    6.92113733847539, 7.65943171113225, 6.93737448932356, 7.06080211169904, 
    6.8843911169438), ln_hba1c_v00 = c(1.75785791755237, 1.94876321803772, 
    1.74919985480926, 1.86717610851281, 1.85159946958407, 1.83098018238134, 
    1.81807677754543), ln_hba1c_v66 = c(1.75440368268429, 2.01223279198639, 
    1.73165554515835, 1.73871024813824, 1.83577635464483, 1.73695123273306, 
    1.79342474854712), ln_hba1c_v01 = c(1.73871024813824, 2.00955541421567, 
    1.72455071953461, 1.75267208052001, 1.90061387414014, 1.81319474994812, 
    1.77495235091167), ln_geaf_tot_v00 = c(7.92632458219889, 
    7.83101368017189, 9.19625564627884, 7.33853719507409, 7.86380504062964, 
    5.63378910283567, 8.62952316388985), ln_geaf_tot_v66 = c(6.74783297533163, 
    7.77385526633194, 8.54614015603788, 6.90775527898214, 8.59130202071245, 
    7.13786649961194, 7.93637419582971), ln_geaf_tot_v01 = c(7.51490874637511, 
    6.44471931905199, 9.40655086276987, 7.87449955275039, 7.99228216582975, 
    8.04073678772979, 8.3874511814324), terciles_peso1_v00 = structure(c(3L, 
    1L, 1L, 2L, 1L, 2L, 3L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_cintura1_v00 = structure(c(3L, 1L, 1L, 1L, 1L, 3L, 
    1L), .Label = c("1", "2", "3"), class = "factor"), terciles_tasis2_e_v00 = structure(c(1L, 
    1L, 1L, 1L, 3L, 3L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_tadias2_e_v00 = structure(c(3L, 3L, 1L, 1L, 3L, 
    2L, 2L), .Label = c("1", "2", "3"), class = "factor"), terciles_p17_total_v00 = structure(c(3L, 
    3L, 3L, 1L, 2L, 2L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_geaf_tot_v00 = structure(c(2L, 2L, 3L, 2L, 2L, 1L, 
    3L), .Label = c("1", "2", "3"), class = "factor"), terciles_glucosa_v00 = structure(c(1L, 
    3L, 2L, 3L, 3L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_albumi_v00 = structure(c(3L, 1L, 2L, 1L, 2L, 2L, 
    2L), .Label = c("1", "2", "3"), class = "factor"), terciles_coltot_v00 = structure(c(2L, 
    3L, 1L, 1L, 1L, 3L, 3L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_hdl_v00 = structure(c(2L, 3L, 1L, 1L, 3L, 3L, 1L
    ), .Label = c("1", "2", "3"), class = "factor"), terciles_ldl_calc_v00 = structure(c(1L, 
    3L, 1L, 1L, 1L, 3L, 3L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_trigli_v00 = structure(c(3L, 2L, 2L, 2L, 1L, 1L, 
    2L), .Label = c("1", "2", "3"), class = "factor"), terciles_hba1c_v00 = structure(c(1L, 
    3L, 1L, 3L, 3L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_peso1_v66 = structure(c(3L, 1L, 1L, 2L, 1L, 2L, 
    3L), .Label = c("1", "2", "3"), class = "factor"), terciles_cintura1_v66 = structure(c(3L, 
    1L, 1L, 1L, 2L, 3L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_tasis2_e_v66 = structure(c(1L, 3L, 1L, 1L, 3L, 2L, 
    1L), .Label = c("1", "2", "3"), class = "factor"), terciles_tadias2_e_v66 = structure(c(3L, 
    2L, 1L, 1L, 3L, 2L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_p17_total_v66 = structure(c(1L, 3L, 2L, 2L, 1L, 
    2L, 1L), .Label = c("1", "2", "3"), class = "factor"), terciles_geaf_tot_v66 = structure(c(1L, 
    2L, 3L, 1L, 3L, 1L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_glucosa_v66 = structure(c(1L, 3L, 1L, 2L, 3L, 2L, 
    1L), .Label = c("1", "2", "3"), class = "factor"), terciles_albumi_v66 = structure(c(2L, 
    1L, 3L, 3L, 3L, 3L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_coltot_v66 = structure(c(2L, 3L, 1L, 1L, 1L, 1L, 
    2L), .Label = c("1", "2", "3"), class = "factor"), terciles_hdl_v66 = structure(c(2L, 
    3L, 2L, 1L, 3L, 2L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_ldl_calc_v66 = structure(c(2L, 3L, 1L, 1L, 1L, 1L, 
    3L), .Label = c("1", "2", "3"), class = "factor"), terciles_trigli_v66 = structure(c(2L, 
    1L, 2L, 2L, 1L, 1L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_hba1c_v66 = structure(c(2L, 3L, 1L, 2L, 3L, 2L, 
    2L), .Label = c("1", "2", "3"), class = "factor"), terciles_peso1_v01 = structure(c(3L, 
    1L, 1L, 2L, 1L, 2L, 3L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_cintura1_v01 = structure(c(2L, 1L, 1L, 1L, 2L, 2L, 
    1L), .Label = c("1", "2", "3"), class = "factor"), terciles_tasis2_e_v01 = structure(c(1L, 
    2L, 1L, 2L, 3L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_tadias2_e_v01 = structure(c(2L, 3L, 1L, 2L, 3L, 
    1L, 2L), .Label = c("1", "2", "3"), class = "factor"), terciles_p17_total_v01 = structure(c(1L, 
    2L, 3L, 2L, 1L, 2L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_geaf_tot_v01 = structure(c(1L, 1L, 3L, 2L, 2L, 2L, 
    3L), .Label = c("1", "2", "3"), class = "factor"), terciles_glucosa_v01 = structure(c(1L, 
    3L, 2L, 3L, 3L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_albumi_v01 = structure(c(3L, 1L, 3L, 1L, 3L, 3L, 
    2L), .Label = c("1", "2", "3"), class = "factor"), terciles_coltot_v01 = structure(c(2L, 
    3L, 2L, 1L, 1L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_hdl_v01 = structure(c(2L, 3L, 1L, 1L, 3L, 2L, 2L
    ), .Label = c("1", "2", "3"), class = "factor"), terciles_ldl_calc_v01 = structure(c(2L, 
    3L, 2L, 1L, 1L, 3L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_trigli_v01 = structure(c(3L, 2L, 3L, 2L, 1L, 2L, 
    1L), .Label = c("1", "2", "3"), class = "factor"), terciles_hba1c_v01 = structure(c(1L, 
    3L, 1L, 2L, 3L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_i_hucpeptide_v00 = structure(c(1L, 1L, 2L, 3L, 2L, 
    2L, 3L), .Label = c("1", "2", "3"), class = "factor"), terciles_i_hucpeptide_v66 = structure(c(3L, 
    1L, 1L, 2L, 2L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_i_hucpeptide_v01 = structure(c(1L, 1L, 2L, 3L, 2L, 
    3L, 2L), .Label = c("1", "2", "3"), class = "factor"), terciles_i_hughrelin_v00 = structure(c(3L, 
    1L, 1L, 1L, 1L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_i_hughrelin_v66 = structure(c(3L, 1L, 1L, 1L, 1L, 
    2L, 2L), .Label = c("1", "2", "3"), class = "factor"), terciles_i_hughrelin_v01 = structure(c(3L, 
    1L, 1L, 1L, 1L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_i_hugip_v00 = structure(c(3L, 1L, 3L, 2L, 3L, 2L, 
    1L), .Label = c("1", "2", "3"), class = "factor"), terciles_i_hugip_v66 = structure(c(3L, 
    1L, 3L, 2L, 3L, 2L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_i_hugip_v01 = structure(c(3L, 1L, 3L, 2L, 3L, 2L, 
    1L), .Label = c("1", "2", "3"), class = "factor"), terciles_i_huglp1_v00 = structure(c(1L, 
    3L, 1L, 2L, 1L, 2L, 3L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_i_huglp1_v66 = structure(c(2L, 3L, 1L, 1L, 1L, 1L, 
    1L), .Label = c("1", "2", "3"), class = "factor"), terciles_i_huglp1_v01 = structure(c(1L, 
    3L, 1L, 1L, 1L, 1L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_i_huglucagon_v00 = structure(c(1L, 1L, 2L, 1L, 1L, 
    1L, 2L), .Label = c("1", "2", "3"), class = "factor"), terciles_i_huglucagon_v66 = structure(c(2L, 
    2L, 1L, 1L, 1L, 1L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_i_huglucagon_v01 = structure(c(1L, 2L, 2L, 2L, 1L, 
    1L, 2L), .Label = c("1", "2", "3"), class = "factor"), terciles_i_huinsulin_v00 = structure(c(1L, 
    1L, 2L, 3L, 2L, 1L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_i_huinsulin_v66 = structure(c(1L, 1L, 1L, 2L, 2L, 
    2L, 2L), .Label = c("1", "2", "3"), class = "factor"), terciles_i_huinsulin_v01 = structure(c(1L, 
    1L, 2L, 3L, 2L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_i_huleptin_v00 = structure(c(1L, 1L, 3L, 2L, 1L, 
    1L, 1L), .Label = c("1", "2", "3"), class = "factor"), terciles_i_huleptin_v66 = structure(c(1L, 
    2L, 2L, 1L, 1L, 1L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_i_huleptin_v01 = structure(c(1L, 2L, 3L, 2L, 1L, 
    1L, 1L), .Label = c("1", "2", "3"), class = "factor"), terciles_i_hupai1_v00 = structure(c(1L, 
    1L, 1L, 3L, 1L, 3L, 3L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_i_hupai1_v66 = structure(c(2L, 1L, 1L, 2L, 1L, 2L, 
    2L), .Label = c("1", "2", "3"), class = "factor"), terciles_i_hupai1_v01 = structure(c(2L, 
    1L, 1L, 3L, 1L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_i_huresistin_v00 = structure(c(1L, 3L, 1L, 3L, 3L, 
    1L, 1L), .Label = c("1", "2", "3"), class = "factor"), terciles_i_huresistin_v66 = structure(c(2L, 
    3L, 1L, 3L, 2L, 1L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_i_huresistin_v01 = structure(c(1L, 3L, 1L, 3L, 2L, 
    1L, 1L), .Label = c("1", "2", "3"), class = "factor"), terciles_i_huvisfatin_v00 = structure(c(1L, 
    2L, 3L, 1L, 1L, 1L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_i_huvisfatin_v66 = structure(c(1L, 2L, 1L, 1L, 1L, 
    1L, 1L), .Label = c("1", "2", "3"), class = "factor"), terciles_i_huvisfatin_v01 = structure(c(1L, 
    2L, 3L, 2L, 1L, 1L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_col_rema_v00 = structure(c(3L, 2L, 2L, 2L, 1L, 1L, 
    2L), .Label = c("1", "2", "3"), class = "factor"), terciles_col_rema_v66 = structure(c(2L, 
    1L, 2L, 2L, 1L, 1L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_col_rema_v01 = structure(c(3L, 2L, 3L, 2L, 1L, 2L, 
    1L), .Label = c("1", "2", "3"), class = "factor"), terciles_homa_v00 = structure(c(1L, 
    1L, 2L, 3L, 2L, 1L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_homa_v66 = structure(c(1L, 1L, 1L, 2L, 3L, 2L, 1L
    ), .Label = c("1", "2", "3"), class = "factor"), terciles_homa_v01 = structure(c(1L, 
    1L, 2L, 3L, 2L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_homa_v66 = structure(c(3L, 2L, 1L, 1L, 3L, 3L, 
    2L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_homa_v01 = structure(c(3L, 
    2L, 2L, 1L, 2L, 3L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_hughrelin_v66 = structure(c(3L, 2L, 3L, 3L, 2L, 
    2L, 3L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_hughrelin_v01 = structure(c(3L, 
    2L, 2L, 3L, 2L, 3L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_huinsulin_v66 = structure(c(3L, 2L, 1L, 1L, 3L, 
    3L, 1L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_huinsulin_v01 = structure(c(3L, 
    2L, 3L, 1L, 2L, 3L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_hucpeptide_v66 = structure(c(3L, 2L, 1L, 1L, 2L, 
    2L, 1L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_hucpeptide_v01 = structure(c(3L, 
    2L, 2L, 1L, 1L, 3L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_huglucagon_v66 = structure(c(3L, 3L, 1L, 1L, 2L, 
    2L, 1L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_huglucagon_v01 = structure(c(2L, 
    2L, 3L, 2L, 3L, 1L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_huleptin_v66 = structure(c(3L, 3L, 1L, 1L, 2L, 
    2L, 1L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_huleptin_v01 = structure(c(3L, 
    3L, 2L, 2L, 3L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_huresistin_v66 = structure(c(3L, 3L, 2L, 3L, 1L, 
    2L, 1L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_huresistin_v01 = structure(c(3L, 
    3L, 2L, 3L, 1L, 2L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_huvisfatin_v66 = structure(c(3L, 3L, 1L, 1L, 2L, 
    2L, 1L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_huvisfatin_v01 = structure(c(3L, 
    2L, 2L, 2L, 2L, 2L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_glucosa_v66 = structure(c(1L, 3L, 1L, 1L, 3L, 
    2L, 2L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_glucosa_v01 = structure(c(2L, 
    3L, 2L, 2L, 3L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_coltot_v66 = structure(c(3L, 1L, 2L, 2L, 3L, 1L, 
    1L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_coltot_v01 = structure(c(3L, 
    3L, 3L, 2L, 2L, 1L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_hdl_v66 = structure(c(2L, 3L, 3L, 3L, 3L, 1L, 
    1L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_hdl_v01 = structure(c(3L, 
    3L, 2L, 3L, 3L, 1L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_ldl_calc_v66 = structure(c(3L, 1L, 2L, 2L, 2L, 
    1L, 1L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_ldl_calc_v01 = structure(c(3L, 
    3L, 3L, 2L, 2L, 1L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_col_rema_v66 = structure(c(2L, 1L, 1L, 1L, 3L, 
    2L, 3L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_col_rema_v01 = structure(c(3L, 
    3L, 3L, 1L, 2L, 3L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_trigli_v66 = structure(c(2L, 2L, 1L, 1L, 3L, 2L, 
    3L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_trigli_v01 = structure(c(3L, 
    3L, 3L, 1L, 2L, 3L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_hba1c_v66 = structure(c(3L, 3L, 3L, 1L, 2L, 1L, 
    2L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_hba1c_v01 = structure(c(2L, 
    3L, 2L, 1L, 3L, 2L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_tasis2_e_v66 = structure(c(3L, 3L, 1L, 2L, 3L, 
    1L, 2L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_tasis2_e_v01 = structure(c(2L, 
    3L, 2L, 3L, 2L, 1L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_tadias2_e_v66 = structure(c(3L, 1L, 1L, 2L, 2L, 
    2L, 1L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_tadias2_e_v01 = structure(c(2L, 
    1L, 2L, 3L, 2L, 1L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_peso1_v66 = structure(c(2L, 2L, 1L, 1L, 3L, 2L, 
    3L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_peso1_v01 = structure(c(2L, 
    2L, 1L, 1L, 3L, 1L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_cintura1_v66 = structure(c(2L, 2L, 1L, 2L, 3L, 
    2L, 3L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_cintura1_v01 = structure(c(1L, 
    2L, 1L, 2L, 3L, 1L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_geaf_tot_v66 = structure(c(1L, 1L, 1L, 1L, 3L, 
    2L, 1L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_geaf_tot_v01 = structure(c(1L, 
    1L, 3L, 2L, 2L, 3L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_p17_total_v66 = structure(c(1L, 2L, 1L, 3L, 2L, 
    2L, 3L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_p17_total_v01 = structure(c(1L, 
    2L, 3L, 3L, 2L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_hupai1_v66 = structure(c(3L, 3L, 1L, 1L, 2L, 1L, 
    1L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_hupai1_v01 = structure(c(3L, 
    3L, 2L, 2L, 2L, 1L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_hugip_v66 = structure(c(3L, 1L, 3L, 2L, 3L, 2L, 
    1L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_hugip_v01 = structure(c(3L, 
    1L, 3L, 2L, 3L, 2L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_d_huglp1_v66 = structure(c(3L, 3L, 2L, 1L, 2L, 1L, 
    1L), .Label = c("1", "2", "3"), class = "factor"), terciles_d_huglp1_v01 = structure(c(3L, 
    1L, 2L, 1L, 1L, 1L, 1L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_ln_trigli_v00 = structure(c(3L, 2L, 2L, 2L, 1L, 
    1L, 2L), .Label = c("1", "2", "3"), class = "factor"), terciles_ln_trigli_v66 = structure(c(2L, 
    1L, 2L, 2L, 1L, 1L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_ln_trigli_v01 = structure(c(3L, 2L, 3L, 2L, 1L, 
    2L, 1L), .Label = c("1", "2", "3"), class = "factor"), terciles_ln_homa_v00 = structure(c(1L, 
    1L, 2L, 3L, 2L, 1L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_ln_homa_v66 = structure(c(1L, 1L, 1L, 2L, 3L, 2L, 
    1L), .Label = c("1", "2", "3"), class = "factor"), terciles_ln_homa_v01 = structure(c(1L, 
    1L, 2L, 3L, 2L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_ln_hba1c_v00 = structure(c(1L, 3L, 1L, 3L, 3L, 2L, 
    2L), .Label = c("1", "2", "3"), class = "factor"), terciles_ln_hba1c_v66 = structure(c(2L, 
    3L, 1L, 2L, 3L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_ln_hba1c_v01 = structure(c(1L, 3L, 1L, 2L, 3L, 2L, 
    2L), .Label = c("1", "2", "3"), class = "factor"), terciles_ln_geaf_tot_v00 = structure(c(2L, 
    2L, 3L, 2L, 2L, 1L, 3L), .Label = c("1", "2", "3"), class = "factor"), 
    terciles_ln_geaf_tot_v66 = structure(c(1L, 2L, 3L, 1L, 3L, 
    1L, 2L), .Label = c("1", "2", "3"), class = "factor"), terciles_ln_geaf_tot_v01 = structure(c(1L, 
    1L, 3L, 2L, 2L, 2L, 3L), .Label = c("1", "2", "3"), class = "factor")), row.names = c(NA, 
-7L), class = "data.frame")

I have created "terciles_variable_v66" with ntile function. The idea is comparing through aov of 3 groups of variables( 3 terciles created with ntile f(x)) created from terciles of other variable, and the iterate to get the rest.

The problem is how can I codify to get individuals of variables according the terciles of one specific variable, and this tercile variable rotates.

I have 2 approaches

  1. sapply: works to get aov of terciles of one self varialbe f.example: d_peso_v66 ~ terciles_d_peso_v66
    But I cant pass it through the rest of vars
modelo2<- sapply(colvars[ ,var], summary(aov(as.formula(paste0("var","~ terciles_", "var"))),dat1))[[var]][["Pr(>F)"]][var]
  1. purrr function
 dat1 %>% 
  purrr::map_dbl(.x, .f = aov(as.formula(paste0("var","~ terciles_", "var"))))) %>% 
      broom::tidy()

I accept recommendations on how to learn to work with these string variants
Thanks in advance

I am not quite sure what you want to do but have a look at this:
Assuming that your data.frame is dat1 you could do:

# names of all variables in dat1:
n <- names(dat1) 
# names of all non terciles variables ending with _v66
v <- n[stringr::str_detect(n,'^terciles',negate = T) & 
       stringr::str_detect(n,'_v66$',negate = F) ] 
# formulas for these variables (i.e. strings to be converted to formulas)
f <- paste0(v," ~ terciles_",v) 
# results of aov for these formulas  in data.frame format
purrr::map_dfr(f, ~aov(as.formula(.),data=dat1) %>% broom::tidy() ) 
1 Like

Let say we calculate the terciles of variable d_peso1_v66. So we have 3 groups with individuals according the levels of this variable. What I am going to do is calculate the aov of the rest of the variables (d_cintura1_v66, d_hughrelin_v66, d_glucosa_v66, d_trigli_v66...) according the groups created with terciles of d_peso_v66. So I have to create terciles of more variables and observe the variance here.
The goal is to see if the d_peso_v66 (weight change at 6 months) changes in same direction with other variables
I hoped I would have explained myself

What you have done, I need it as well, but I need to pass the variables throug the terciles created. You just passed the variable with its correspondant terciles, I need to pass all variables to the tercile. And that repeat it for all variables. I won't pick all variables up, but several of them I will need it.

I guess you don't understand what I have to do

Thank you anyway for the effort