Home > Back-end >  Print the labels of a list of variables
Print the labels of a list of variables

Time:12-16

What I am trying to do is print the labels of a set of variables contained in a dataframe. I would like to get the plain text out of the variables. The list of variables is:

#The list of characters 

vars <- c("hc", "prot", "gratot", "mo", "po", "sa", "alcoholg", "energiat",  "fibra" , "colest" , "fit" , "linolenico")
vars <- sort(vars)

#The df where the variables are contained with the attributes is dat1

for (i in vars_dieta) {
x <- print(attr(dat1, "label"))
}

# or

lapply(vars_dieta, attr(dat1, which = "label"))

The database comes from spss after importing, with read_sav and as_factor, but as I paste right below, you will see exactly how the database is made up.

dat$hc

attr(,"label")
[1] "CFCA: Hidratos de carbono (g/día)"
attr(,"format.spss")
[1] "F13.9"
attr(,"display_width")
[1] 13

# The database

dat1 <- structure(list(hc = structure(c(230.693, 219.261, 293.859, 185.046, 
290.647, 179.877, 163.61, 226.767, 237.187, 215.529, 231.871, 
219.799, 313.474, 213.825, 266.067, 273.789, 331.974, 236.96, 
240.23, 257.44, 240.026, 441.27, 298.091, 282.346, 338.679, 344.482, 
205.039, 408.26, 209.583, 206.113, 145.448, 218.672, 182.319, 
387.565, 239.381, 255.337, 156.895, 140.789, 228.158, 170.847, 
145.242, 135.324, 173.325, 211.33, 190.705, 211.179, 119.748, 
228.65, 174.01, 150.372, 170.041, 183.002, 175.521, 268.408, 
177.078, 263.456, 214.696, 217.049, 210.993, 231.577, 178.468, 
185.717, 178.53, 276.308, 240.677, 258.154, 252.059, 268.494, 
256.204, 247.231, 142.259, 218.504, 244.195, 189.491, 266.341, 
230.099, 170.482, 441.223, 258.654, 374.204, 259.538, 261.264, 
255.508, 233.714, 228.232, 313.693, 486.645, 246.935, 198.881, 
193.139, 214.894, 273.364, 312.362, 258.181, 297.027, 199.269, 
274.294, 223.725, 226.847, 222.784, 190.2, 189.398, 151.763, 
247.258, 141.653, 212.13, 220.985, 353.483, 280.084, 244.07, 
214.19, 317.906, 323.38, 119.814, 282.184, 302.622, 250.576, 
281.525, 254.08, 374.777, 232.324, 333.179, 485.481, 245.36, 
275.62, 356.797, 222.547, 295.833, 232.076, 238.53, 208.007, 
182.662, 268.2, 223.692, 271.954, 159.47, 231.784, 183.465, 152, 
155.572, 143.51, 135.732, 229.224, 173.907, 172.249, 370.952, 
160.821, 183.978, 159.327, 159.559, 89.741), label = "CFCA: Hidratos de carbono (g/día)", format.spss = "F13.9", display_width = 13L), 
    prot = structure(c(81.729, 82.578, 80.662, 68.878, 96.12, 
    81.239, 79.644, 63.994, 98.849, 105.171, 114.676, 102.529, 
    96.756, 134.653, 101.368, 117.145, 113.136, 82.581, 95.757, 
    111.079, 98.818, 126.634, 121.541, 114.376, 131.567, 85.932, 
    85.488, 124.433, 119.113, 118.75, 108.386, 101.582, 95.243, 
    155.193, 106.031, 97.692, 83.388, 73.258, 108.006, 70.92, 
    69.179, 76.258, 83.603, 65.39, 82.258, 77.735, 86.489, 73.553, 
    97.218, 79.117, 80.672, 87.096, 72.436, 97.012, 68.878, 101.447, 
    101.158, 89.058, 70.261, 84.105, 80.543, 66.761, 79.722, 
    112.796, 107.256, 129.607, 123.97, 95.669, 90.564, 97.101, 
    74.133, 80.542, 93.962, 68.558, 85.29, 88.855, 81.988, 99.175, 
    89.647, 88.89, 94.034, 67.229, 63.265, 81.417, 85.716, 82.415, 
    120.431, 82.453, 81.199, 110.601, 96.591, 122.377, 95.466, 
    95.698, 120.563, 75.446, 78.304, 105.92, 64.105, 55.356, 
    58.892, 61.881, 62.499, 63.884, 58.558, 76.469, 63.713, 85.228, 
    78.618, 75.469, 70.841, 87.631, 82.727, 53.779, 78.869, 76.518, 
    114.562, 120.435, 99.251, 91.892, 73.883, 101.086, 106.261, 
    109.385, 81.463, 133.594, 72.958, 110.315, 109.527, 107.269, 
    89.041, 100.081, 106.141, 126.01, 127.185, 98.987, 111.513, 
    113.386, 96.246, 99.381, 78.632, 98.67, 79.363, 103.707, 
    123.755, 179.161, 97.847, 113.164, 100.464, 87.237, 64.408
    ), label = "CFCA: proteinas (g/día)", format.spss = "F13.9", display_width = 13L), 
    gratot = structure(c(104.232, 83.461, 101.03, 78.998, 105.364, 
    96.057, 57.706, 55.549, 132.129, 117.275, 116.273, 85.622, 
    102.483, 161.421, 119.794, 121.244, 111.881, 106.379, 91.927, 
    107.036, 102.698, 172.983, 132.333, 117.561, 156.322, 113.514, 
    106.141, 157.12, 160.613, 131.885, 115.641, 87.151, 113.074, 
    169.398, 116.172, 107.255, 60.372, 55.361, 100.002, 57.939, 
    58.816, 66.906, 83.102, 96.74, 104.009, 83.002, 78.664, 84.8, 
    111.92, 68.625, 78.631, 71.015, 64.997, 109.804, 106.53, 
    108.722, 102.954, 99.649, 85.906, 87.83, 83.754, 112.611, 
    99.204, 157.618, 104.072, 132.26, 136.923, 164.095, 100.278, 
    118.911, 72.454, 62.62, 60.705, 46.047, 106.83, 86.41, 67.963, 
    69.052, 94.615, 78.451, 89.707, 82.243, 60.5, 89.102, 48.042, 
    77.455, 121.191, 81.699, 95.767, 102.041, 92.682, 86.262, 
    103.588, 68.942, 76.341, 51.316, 77.068, 80.433, 68.78, 81.286, 
    98.088, 56.282, 53.843, 90.833, 76.141, 55.707, 50.421, 73.055, 
    83.398, 90.634, 82.95, 81.377, 90.855, 49.397, 74.594, 77.508, 
    95.664, 75.191, 100.236, 97.844, 76.927, 64.636, 108.666, 
    114.747, 62.282, 98.975, 72.558, 108.54, 89.715, 124.178, 
    99.856, 78.046, 124.541, 84.947, 98.385, 48.166, 118.131, 
    71.302, 134.867, 105.288, 61.154, 101.843, 109.757, 98.237, 
    55.093, 138.009, 77.598, 81.632, 106.979, 76.08, 72.292), label = "CFCA: Lípidos (g/día)", format.spss = "F13.9", display_width = 13L), 
    mo = structure(c(54.8, 45.763, 51.364, 44.481, 56.14, 49.656, 
    30.347, 26.447, 73.413, 59.72, 57.939, 41.644, 54.739, 79.568, 
    61.446, 62.266, 48.146, 57.754, 42.661, 54.828, 53.614, 78.347, 
    65.4, 58.473, 75.786, 58.565, 56.633, 80.982, 75.763, 70.088, 
    61.392, 41.848, 56.472, 79.674, 57.469, 52.39, 29.865, 28.564, 
    54.617, 33.011, 18.661, 32.342, 46.648, 51.752, 51.708, 36.74, 
    40.648, 46.444, 55.587, 30.443, 33.82, 31.325, 26.621, 49.147, 
    56.262, 49.003, 56.169, 50.324, 51.022, 48.679, 37.02, 63.323, 
    51.706, 79.291, 55.189, 67.672, 75.131, 82.236, 54.141, 61.407, 
    36.539, 30.538, 26.777, 24.022, 55.786, 46.399, 33.433, 30.523, 
    51.145, 39.445, 49.722, 46.197, 28.939, 47.008, 25.045, 43.738, 
    61.391, 46.139, 50.753, 53.455, 43.379, 47.007, 52.43, 35.776, 
    36.048, 26.397, 43.523, 39.129, 40.633, 46.315, 54.141, 32.793, 
    26.321, 40.339, 33.766, 29.616, 25.062, 33.511, 45.581, 48.16, 
    45.625, 29.869, 40.757, 19.003, 35.363, 37.346, 45.731, 35.034, 
    42.321, 45.279, 43.946, 24.031, 56.197, 57.003, 30.526, 33.353, 
    33.134, 53.716, 41.885, 57.741, 42.988, 34.964, 56.097, 36.345, 
    42.367, 24.71, 58.373, 35.239, 69.874, 54.296, 30.208, 54.197, 
    58.138, 46.471, 21.91, 63.942, 32.339, 41.334, 45.217, 34.048, 
    42.398), label = "CFCA: AGM-monoinsaturados (g/día)", format.spss = "F12.9", display_width = 12L), 
    po = structure(c(13.33, 13.321, 16.063, 11.753, 14.948, 11.641, 
    9.145, 12.26, 17.466, 13.211, 18.659, 14.334, 14.554, 22.203, 
    14.017, 14.899, 26.048, 15.231, 12.436, 17.227, 16.979, 30.809, 
    16.298, 19.72, 30.809, 15.512, 13.803, 23.34, 16.04, 13.127, 
    15.66, 10.89, 17.408, 24.363, 19.932, 17.676, 7.368, 6.552, 
    17.436, 8.36, 14.107, 7.759, 10.817, 13.462, 25.005, 16.904, 
    9.119, 10.399, 12.868, 12.495, 13.177, 7.165, 12.531, 16.404, 
    18.677, 18.346, 14.118, 20.235, 11.059, 12.26, 12.437, 13.2, 
    15.365, 28.611, 15.215, 16.73, 16.36, 24.698, 13.754, 13.431, 
    9.601, 6.348, 12.711, 6.789, 17.808, 12.099, 7.431, 12.583, 
    9.842, 8.914, 9.623, 9.616, 8.48, 12.237, 6.183, 11.719, 
    20.61, 12.106, 12.66, 14.88, 15.447, 9.936, 13.01, 7.14, 
    10.035, 6.755, 11.023, 15.627, 8.948, 12.334, 9.725, 8.784, 
    8.925, 18.547, 20.497, 7.431, 11.012, 15.02, 13.073, 15.23, 
    12.423, 20.543, 21.123, 7.142, 12.601, 13.271, 17.365, 12.619, 
    13.814, 17.168, 8.895, 6.047, 14.735, 17.996, 11.188, 27.129, 
    19.92, 14.603, 12.444, 25.665, 21.717, 8.339, 34.086, 11.68, 
    17.653, 5.675, 20.291, 8.754, 16.352, 14.743, 9.161, 13.046, 
    19.189, 18.021, 11.064, 21.682, 13.118, 10.075, 25.505, 13.905, 
    9.629), label = "CFCA: AGP-poliinsaturados (g/día)", format.spss = "F12.9", display_width = 12L), 
    sa = structure(c(26.419, 15.449, 23.274, 15.415, 26.991, 
    25.3, 14.278, 9.319, 30.999, 34.65, 27.756, 23.167, 23.761, 
    52.353, 37.013, 34.729, 28.098, 26.978, 30.836, 22.715, 21.036, 
    47.56, 36.664, 29.111, 38.56, 28.2, 25.569, 47.028, 57.253, 
    41.479, 27.965, 25.899, 32.106, 55.22, 27.845, 24.767, 15.822, 
    16.866, 21.067, 14.298, 14.613, 19.191, 17.914, 23.831, 24.514, 
    18.95, 22.47, 20.153, 28.74, 16.715, 23.362, 22.008, 21.606, 
    31.881, 22.392, 28.19, 28.276, 21.181, 18.417, 19.656, 28.103, 
    29.084, 23.442, 45.928, 25.623, 43.162, 39.369, 41.407, 25.135, 
    34.893, 14.998, 20.177, 12.242, 10.124, 23.366, 19.374, 18.992, 
    18.709, 27.042, 21.674, 20.974, 20.976, 13.929, 21.588, 11.174, 
    14.925, 30.619, 17.289, 22.923, 24.58, 22.811, 20.756, 26.515, 
    19.116, 23.41, 13.677, 16.185, 21.159, 13.369, 17.582, 28.474, 
    14.502, 12.343, 24.443, 17.154, 14.598, 9.097, 17.957, 16.927, 
    17.992, 16.934, 22.683, 20.498, 16.458, 21.765, 23.57, 21.659, 
    18.849, 31.928, 26.417, 16.145, 24.575, 27.499, 27.699, 11.189, 
    21.917, 14.354, 29.687, 21.267, 33.812, 25.064, 22.22, 22.063, 
    23.902, 24.543, 11.745, 26.299, 17.712, 28.354, 28.072, 19.706, 
    33.988, 27.042, 30.612, 15.335, 38.856, 20.625, 22.137, 24.68, 
    22.618, 15.179), label = "CFCA: AGS-saturados (g/día)", format.spss = "F12.9", display_width = 12L), 
    alcoholg = structure(c(0, 0, 0, 5.919, 0, 4.943, 0.6, 10.23, 
    0.693, 1.461, 1.387, 0.6, 53.177, 4.987, 3.075, 28.561, 0, 
    0.6, 3.547, 0.6, 0, 12.699, 5.87, 4.384, 25.18, 26, 80.662, 
    9.599, 11.861, 2.086, 0, 4.384, 12.616, 4.28, 5.98, 28.393, 
    0, 1.293, 21.929, 4.04, 0.682, 1.975, 10.943, 7.525, 2.168, 
    1.293, 2.061, 27.061, 5.057, 14.819, 15.384, 22.456, 1.486, 
    27.333, 26, 0, 0.6, 0.693, 0, 6.025, 0.6, 0, 1.11, 27.701, 
    0, 4.457, 0, 7.958, 21.484, 0, 0, 0, 0.693, 0, 0, 1.486, 
    36.23, 30.384, 10.4, 8.038, 10.4, 4.457, 0, 0, 12.182, 1.775, 
    0, 11.733, 11.082, 0, 0, 0, 0, 0.693, 8.841, 0, 11.082, 20.63, 
    2.155, 7.071, 0, 0, 0, 5.343, 0, 11.082, 0, 55.557, 0.682, 
    4.457, 0, 10.23, 0, 1.486, 0.693, 21.578, 1.293, 0, 0, 41.25, 
    0, 0, 0, 0, 41.643, 0, 0, 12.211, 3.857, 12.757, 0.693, 0, 
    0, 0.6, 10.4, 0, 13.439, 0, 17.141, 20.63, 5.139, 1.461, 
    20.63, 0, 0.682, 0, 0, 11.082, 1.461, 0, 0.693), label = "CFCA: gramos de alcohol puro (vino tinto, otros vinos, cerveza y destilados)", format.spss = "F11.8", display_width = 11L), 
    energiat = structure(c(2187.775, 1958.507, 2407.359, 1768.105, 
    2495.343, 1943.577, 1496.567, 1734.6, 2538.161, 2348.509, 
    2442.351, 2064.112, 2935.506, 2881.607, 2569.41, 2854.857, 
    2787.371, 2239.773, 2196.123, 2441.603, 2279.663, 3917.352, 
    2910.616, 2675.63, 3464.147, 2925.282, 2682.011, 3612.038, 
    2843.332, 2501.013, 2056.106, 2096.061, 2216.22, 3725.579, 
    2469.059, 2576.162, 1504.484, 1363.487, 2398.173, 1516.796, 
    1391.808, 1462.309, 1852.227, 2030.214, 2043.108, 1911.726, 
    1547.352, 2161.435, 2127.59, 1639.314, 1818.225, 1876.721, 
    1587.201, 2641.25, 2124.59, 2438.109, 2194.199, 2126.127, 
    1898.165, 2095.374, 1794.028, 2023.409, 1933.615, 3168.886, 
    2328.38, 2772.581, 2736.422, 2989.209, 2439.969, 2447.533, 
    1517.656, 1759.764, 1903.823, 1446.623, 2367.995, 2063.907, 
    1875.16, 2995.753, 2317.543, 2614.696, 2294.448, 2085.359, 
    1819.591, 2062.44, 1773.441, 2293.951, 3519.021, 2134.981, 
    2059.795, 2133.326, 2080.077, 2359.319, 2563.605, 2040.847, 
    2419.323, 1560.702, 2181.58, 2186.888, 1797.909, 1893.632, 
    1879.162, 1511.654, 1341.633, 2099.468, 1486.111, 1733.326, 
    1592.581, 2801.242, 2190.162, 2125.063, 1886.674, 2426.152, 
    2442.117, 1149.346, 2120.413, 2365.176, 2330.579, 2284.563, 
    2315.447, 3036.019, 1917.17, 2318.788, 3344.965, 2451.706, 
    2280.373, 2852.342, 1835.044, 2686.926, 2200.847, 2590.097, 
    2091.746, 1833.39, 2618.234, 2167.53, 2554.821, 1467.321, 
    2530.448, 1829.123, 2326.773, 2111.813, 1474.929, 1864.425, 
    2366.571, 1994.585, 1684.627, 3442.536, 1733.056, 2000.833, 
    2012.205, 1671.908, 1272.081), label = "CFCA: energia total (Kcal)", format.spss = "F13.8", display_width = 13L), 
    fibra = structure(c(25.034, 30.364, 32.947, 34.616, 35.238, 
    21.252, 27.337, 36.418, 38.043, 36.198, 32.76, 32.022, 30.503, 
    16.376, 35.188, 35.138, 32.745, 38.222, 28.138, 42.888, 42.888, 
    33.714, 24.431, 22.557, 35.894, 37.879, 18.598, 24.916, 21.062, 
    32.809, 26.855, 29.216, 16.34, 35.149, 37.29, 26.698, 17.644, 
    11.694, 24.148, 23.661, 23.502, 16.07, 17.538, 22.796, 18.562, 
    17.9, 14.997, 19.233, 18.353, 20.376, 16.95, 17.797, 10.443, 
    25.176, 23.556, 26.164, 20.499, 35.479, 17.948, 17.575, 17.764, 
    16.905, 24.283, 19.878, 22.032, 30.288, 20.622, 24.863, 23.778, 
    28.2, 24.068, 16.944, 28.006, 17.243, 29.544, 24.548, 21.078, 
    27.06, 19.073, 28.445, 24.82, 26.972, 23.256, 22.856, 30.207, 
    54.289, 31.437, 19.357, 20.69, 16.265, 20.765, 48.651, 25.611, 
    19.73, 25.937, 22.969, 30.403, 25.573, 24.594, 17.904, 29.352, 
    28.023, 17.173, 22.587, 18.788, 16.125, 19.06, 42.654, 39.922, 
    32.427, 29.618, 22.848, 26.63, 21.103, 35.947, 28.197, 39.949, 
    46.188, 38.762, 26.383, 31.113, 26.897, 50.296, 26.654, 46.606, 
    38.366, 28.889, 29.061, 27.366, 24.467, 27.869, 20.865, 34.532, 
    24.214, 24.018, 19.901, 27.445, 24.431, 19.429, 16.79, 19.121, 
    13.611, 20.209, 20.882, 25.97, 59.214, 21.505, 26.201, 29.372, 
    19.278, 15.012), label = "CFCA: fibra (g/día)", format.spss = "F12.9", display_width = 12L), 
    colest = structure(c(292.292, 234.403, 311.061, 309.81, 389.591, 
    365.714, 210.857, 152.323, 375.468, 486.519, 459.621, 436.767, 
    760.616, 791.953, 477.64, 656.042, 417.236, 270.913, 424.126, 
    362.431, 357.637, 645.792, 433.148, 468.559, 636.255, 337.357, 
    427.762, 670.833, 554.944, 435.904, 459.898, 422.695, 374.214, 
    808.413, 448.603, 328.825, 360.321, 627.991, 496.343, 373.879, 
    330.504, 382.86, 408.308, 500.358, 443.013, 176.641, 476.749, 
    263.728, 425.362, 197.08, 357.832, 368.134, 299.696, 434.816, 
    323.69, 788.737, 418.956, 269.667, 423.579, 381.32, 295.858, 
    392.803, 329.393, 602.866, 450.496, 577.14, 551.928, 512.168, 
    387.182, 345.856, 203.316, 311.166, 344.272, 311.559, 305.653, 
    347.938, 267.418, 333.836, 315.937, 343.666, 306.224, 283.629, 
    248.75, 324.878, 197.84, 248.516, 395.779, 295.07, 295.512, 
    523.377, 387.157, 389.028, 398.556, 385.894, 550.661, 349.28, 
    348.609, 556.693, 290.876, 241.045, 222.341, 336.497, 252.388, 
    347.494, 312.018, 308.151, 141.061, 260.633, 182.94, 433.033, 
    218.847, 328.485, 270.994, 153.986, 308.897, 292.976, 312.58, 
    371.784, 402.76, 298.284, 174.367, 254.207, 470.33, 615.289, 
    253.661, 371.31, 119.607, 378.459, 301.708, 420.134, 363.415, 
    433.725, 479.324, 395.8, 411.285, 338.661, 303.392, 297.949, 
    434.388, 342.646, 303.311, 317.007, 251.65, 426.225, 718.114, 
    547.932, 393.587, 438.148, 445.87, 382.049, 320.85), label = "CFCA: colesterol (mg/día)", format.spss = "F13.9", display_width = 13L), 
    fit = structure(c(339.922, 315.542, 404.647, 364.088, 498.291, 
    244.423, 247.189, 375.655, 419.487, 388.218, 396.79, 326.238, 
    365.281, 353.282, 398.624, 365.927, 467.1, 475.742, 291.558, 
    425.783, 422.725, 698.814, 456.862, 424.385, 563.345, 391.33, 
    252.158, 441.997, 247.364, 388.587, 324.002, 277.878, 248.317, 
    530.604, 419.871, 403.888, 210.406, 143.809, 335.087, 244.036, 
    226.68, 206.883, 268.092, 360.66, 355.386, 320.801, 182.076, 
    273.722, 213.099, 244.464, 250.584, 223.602, 236.27, 354.855, 
    331.032, 433.879, 304.107, 361.363, 293.339, 259.354, 216.02, 
    293.871, 286.758, 405.324, 332.195, 383.396, 343.854, 407.924, 
    345.535, 340.41, 240.195, 238.605, 294.76, 195.426, 442.459, 
    279.637, 200.042, 389.739, 320.371, 373.194, 268.11, 350.152, 
    286.152, 312.187, 287.563, 414.003, 527.316, 272.864, 321.137, 
    294.131, 303.87, 361.447, 401.225, 290.593, 326.021, 221.007, 
    400.581, 330.183, 274.767, 221.96, 327.947, 331.23, 198.028, 
    403.069, 341.074, 203.165, 290.3, 396.478, 407.383, 435.858, 
    314.404, 454.332, 456.048, 172.123, 327.577, 357.056, 384.323, 
    442.078, 368.751, 327.79, 294.917, 300.832, 466.827, 347.018, 
    256.395, 572.791, 393.55, 477.508, 322.338, 402.796, 349.768, 
    216.704, 499.459, 276.158, 311.367, 184.701, 376.135, 234.138, 
    291.059, 243.338, 216.852, 216.491, 406.164, 306.246, 297.673, 
    484.018, 261.554, 263.217, 476.303, 279.066, 197.733), label = "CFCA: fitosteroles (g/día)", format.spss = "F13.9", display_width = 13L), 
    linolenico = structure(c(1.212, 0.981, 1.776, 1.011, 1.024, 
    0.938, 0.882, 1.248, 1.501, 1.785, 1.919, 1.322, 1.071, 2.138, 
    1.312, 1.527, 2.96, 0.984, 1.006, 1.864, 1.824, 2.527, 1.249, 
    1.6, 2.815, 1.25, 0.983, 1.648, 1.966, 1.581, 1.544, 1.039, 
    1.985, 2.962, 1.944, 1.736, 0.642, 0.73, 1.702, 0.886, 2.019, 
    0.673, 1.055, 1.143, 2.34, 0.963, 1.212, 1.005, 1.336, 1.637, 
    1.59, 0.704, 0.749, 1.286, 1.61, 1.552, 1.386, 1.857, 1.009, 
    1.073, 1.753, 1.075, 1.745, 2.108, 1.427, 1.861, 1.875, 2.068, 
    1.241, 1.516, 1.111, 0.615, 1.418, 0.496, 1.625, 1.103, 0.819, 
    1.483, 0.841, 0.745, 0.931, 0.951, 0.992, 0.996, 0.609, 0.796, 
    1.361, 1.063, 1.019, 1.095, 1.093, 1.085, 1.06, 0.811, 1.014, 
    0.673, 0.865, 1.199, 0.644, 0.836, 0.86, 0.557, 0.763, 0.665, 
    0.663, 0.635, 0.452, 1.514, 1.098, 1.187, 0.983, 0.786, 0.696, 
    0.783, 0.664, 0.797, 1.669, 1.136, 1.279, 1.19, 0.691, 0.726, 
    0.992, 0.971, 0.827, 0.926, 2.344, 0.833, 1.329, 3.173, 2.335, 
    0.926, 3.405, 1.474, 1.138, 0.52, 1.954, 0.896, 1.024, 1.538, 
    0.948, 1.456, 1.043, 1.857, 0.61, 2.193, 1.558, 1.047, 1.24, 
    1.267, 0.976), label = "CFCA: ac. linolenico (g/día)", format.spss = "F11.9", display_width = 11L)), row.names = c(NA, 
-151L), class = c("tbl_df", "tbl", "data.frame"))

CodePudding user response:

The label is an attribute of the single columns not of the dataframe. Hence do:

for (x in names(dat1)) {
  print(attr(dat1[[x]], which = "label"))
}
#> [1] "CFCA: Hidratos de carbono (g/día)"
#> [1] "CFCA: proteinas (g/día)"
#> [1] "CFCA: Lípidos (g/día)"
#> [1] "CFCA: AGM-monoinsaturados (g/día)"
#> [1] "CFCA: AGP-poliinsaturados (g/día)"
#> [1] "CFCA: AGS-saturados (g/día)"
#> [1] "CFCA: gramos de alcohol puro (vino tinto, otros vinos, cerveza y destilados)"
#> [1] "CFCA: energia total (Kcal)"
#> [1] "CFCA: fibra (g/día)"
#> [1] "CFCA: colesterol (mg/día)"
#> [1] "CFCA: fitosteroles (g/día)"
#> [1] "CFCA: ac. linolenico (g/día)"
  • Related