I have the following data:
08001 08003 08005 08006 08007 08009 08010_AM 08014_AM 0801501
08001 4875.276, 4875.276 8.448, 8.448 16.876, 16.876 14.56, 14.56 NULL 15.066, 15.066 24.953, 24.953 7.229, 7.229 7.074, 7.074
08003 15.632 3663.7 15.794 129.029 13.371 145.019 NULL 12.382 180.696
08005 10.611 4.911 2474.452 29.844 NULL 43.95 NULL 347.076 NULL
08006 7.291 69.755 29.844 10841.55 4947.665 200.296 NULL 25.047 19.926
08007 NULL 33.67 17.269 4954.248 3875.372 111.159 NULL NULL 9.84
08009 32.811 106.313 58.019 145.959 158.566 2791.247 NULL 6.568 12.59
08010_AM 40.875, 40.875 NULL 4.341, 4.341 NULL NULL NULL 3039.333, 3039.333 4.341, 4.341 NULL
08014_AM 4.732, 4.732 10.249, 10.249 311.877, 311.877 6.568, 6.568 NULL 10.831, 10.831 4.341, 4.341 420.177, 420.177 6.172, 6.172
0801501 12.344 220.281 NULL 32.741 NULL 18.797 NULL 6.172 1069.609
0801502 23.21 293.464 13.865 34.51 5.624 29.219 NULL NULL 4779.908
Where some of the columns have two numeric values in them. I can use the following to map over the columns and take an average:
mutate(across(everything(), ~ map_dbl(.x, mean, na.rm = TRUE)))
However, this takes too long on the whole dataset. I notice that all of the duplicate column numerics are the same, so my question is how can I change the map function to instead of computing the mean over the two numerics, take the first numeric value?
i.e. in column 1 08001 there are the values 40.875, 40.875, so instead of taking the average of these two numbers, how can I just extract the first number?
Data:
df <- structure(list(`08001` = list(c(4875.276, 4875.276), 15.632,
10.611, 7.291, NULL, 32.811, c(40.875, 40.875), c(4.732,
4.732), 12.344, 23.21), `08003` = list(c(8.448, 8.448), 3663.7,
4.911, 69.755, 33.67, 106.313, NULL, c(10.249, 10.249), 220.281,
293.464), `08005` = list(c(16.876, 16.876), 15.794, 2474.452,
29.844, 17.269, 58.019, c(4.341, 4.341), c(311.877, 311.877
), NULL, 13.865), `08006` = list(c(14.56, 14.56), 129.029,
29.844, 10841.553, 4954.248, 145.959, NULL, c(6.568, 6.568
), 32.741, 34.51), `08007` = list(NULL, 13.371, NULL, 4947.665,
3875.372, 158.566, NULL, NULL, NULL, 5.624), `08009` = list(
c(15.066, 15.066), 145.019, 43.95, 200.296, 111.159, 2791.247,
NULL, c(10.831, 10.831), 18.797, 29.219), `08010_AM` = list(
c(24.953, 24.953), NULL, NULL, NULL, NULL, NULL, c(3039.333,
3039.333), c(4.341, 4.341), NULL, NULL), `08014_AM` = list(
c(7.229, 7.229), 12.382, 347.076, 25.047, NULL, 6.568, c(4.341,
4.341), c(420.177, 420.177), 6.172, NULL), `0801501` = list(
c(7.074, 7.074), 180.696, NULL, 19.926, 9.84, 12.59, NULL,
c(6.172, 6.172), 1069.609, 4779.908), `0801502` = list(c(26.747,
26.747), 305.18, 17.419, 27.801, 5.624, 20.512, NULL, NULL, 4948.395,
3647.42)), row.names = c("08001", "08003", "08005", "08006",
"08007", "08009", "08010_AM", "08014_AM", "0801501", "0801502"
), class = "data.frame")