Home > database >  fill dates in R
fill dates in R

Time:11-23

I'm trying to fill a vector of dates in a data frame but after running this code:

dades_aux %>%
  complete(first_date = seq(min(data_minima), max(data_minima), by = "days"))

I receive this error:

Error: Join columns must be present in data. x Problem with first_date. Run rlang::last_error() to see where the error occurred.

this is the dput of my data:

> dput(dades_aux)
structure(list(data_minima = structure(c(17057, 17136, 17241, 
17246, 17257, 17276, 17286, 17335, 17337, 17339, 17386, 17405, 
17411, 17412, 17413, 17414, 17416, 17421, 17422, 17423, 17424, 
17427, 17430, 17431, 17434, 17436, 17437, 17444, 17445, 17448, 
17450, 17454, 17457, 17459, 17460, 17461, 17464, 17465, 17467, 
17469, 17472, 17474, 17476, 17477, 17478, 17479, 17482, 17491, 
17492, 17493, 17497, 17498, 17499, 17501, 17511, 17512, 17515, 
17516, 17518, 17519, 17520, 17521, 17522, 17535, 17541, 17546, 
17547, 17551, 17552, 17553, 17555, 17556, 17557, 17559, 17561, 
17562, 17563, 17568, 17573, 17575, 17576, 17578, 17580, 17582, 
17583, 17585, 17588, 17591, 17594, 17596, 17598, 17599, 17602, 
17603, 17613, 17616, 17617, 17624, 17625, 17628, 17630, 17632, 
17637, 17639, 17640, 17645, 17646, 17647, 17649, 17653, 17655, 
17658, 17659, 17660, 17661, 17662, 17664, 17665, 17666, 17667, 
17668, 17669, 17670, 17672, 17673, 17674, 17675, 17676, 17678, 
17680, 17682, 17684, 17687, 17688, 17689, 17690, 17693, 17694, 
17695, 17696, 17697, 17700, 17702, 17703, 17708, 17709, 17710, 
17711, 17714, 17715, 17717, 17718, 17721, 17722, 17723, 17724, 
17725, 17728, 17729, 17730, 17731, 17735, 17736, 17737, 17738, 
17740, 17742, 17743, 17744, 17745, 17750, 17751, 17752, 17756, 
17758, 17759, 17763, 17765, 17767, 17772, 17773, 17774, 17777, 
17778, 17779, 17780, 17781, 17784, 17786, 17788, 17789, 17791, 
17792, 17794, 17799, 17800, 17808, 17810, 17811, 17812, 17813, 
17814, 17815, 17819, 17820, 17823, 17825, 17826, 17827, 17833, 
17834, 17836, 17840, 17841, 17842, 17843, 17844, 17848, 17849, 
17850, 17851, 17854, 17857, 17861, 17862, 17863, 17864, 17866, 
17867, 17868, 17869, 17870, 17876, 17878, 17879, 17880, 17881, 
17883, 17884, 17886, 17887, 17888, 17889, 17892, 17893, 17895, 
17896, 17898, 17899, 17900, 17901, 17904, 17905, 17906, 17907, 
17910, 17912, 17913, 17914, 17916, 17917, 17919, 17920, 17921, 
17924, 17925, 17926, 17927, 17928, 17932, 17933, 17934, 17935, 
17936, 17937, 17938, 17940, 17941, 17942, 17943, 17946, 17947, 
17948, 17949, 17950, 17952, 17954, 17956, 17958, 17959, 17960, 
17961, 17963, 17966, 17967, 17968, 17969, 17970, 17972, 17973, 
17975, 17976, 17977, 17978, 17980, 17981, 17982, 17983, 17984, 
17987, 17990, 17991, 17994, 17995, 17996, 18001, 18002, 18003, 
18004, 18010, 18011, 18017, 18018, 18019, 18022, 18023, 18024, 
18025, 18026, 18030, 18031, 18033, 18034, 18036, 18037, 18038, 
18039, 18040, 18043, 18044, 18045, 18046, 18047, 18050, 18051, 
18052, 18053, 18054, 18058, 18059, 18060, 18061, 18064, 18065, 
18066, 18067, 18068, 18069, 18070, 18071, 18072, 18073, 18074, 
18075, 18080, 18081, 18082, 18083, 18084, 18085, 18086, 18087, 
18088, 18089, 18092, 18093, 18094, 18097, 18099, 18100, 18102, 
18106, 18107, 18108, 18109, 18110, 18113, 18115, 18116, 18117, 
18120, 18121, 18122, 18129, 18131, 18134, 18135, 18136, 18137, 
18138, 18141, 18142, 18143, 18144, 18145, 18146, 18147, 18148, 
18149, 18150, 18151, 18152, 18153, 18154, 18156, 18157, 18158, 
18159, 18162, 18164, 18165, 18166, 18169, 18170, 18171, 18172, 
18173, 18174, 18175, 18176, 18177, 18178, 18179, 18180, 18181, 
18183, 18184, 18185, 18186, 18190, 18191, 18192, 18193, 18194, 
18197, 18198, 18199, 18200, 18203, 18204, 18205, 18206, 18207, 
18208, 18210, 18211, 18212, 18214, 18215, 18219, 18220, 18221, 
18226, 18227, 18228, 18229, 18232, 18233, 18234, 18235, 18239, 
18240, 18241, 18242, 18243, 18246, 18247, 18248, 18252, 18253, 
18254, 18256, 18257, 18260, 18262, 18263, 18265, 18266, 18269, 
18270, 18271, 18272, 18275, 18276, 18277, 18278, 18279, 18281, 
18282, 18283, 18284, 18285, 18286, 18289, 18290, 18292, 18294, 
18296, 18297, 18298, 18299, 18300, 18301, 18303, 18304, 18305, 
18306, 18307, 18308, 18309, 18311, 18312, 18313, 18317, 18318, 
18319, 18320, 18323, 18324, 18325, 18326, 18327, 18330, 18332, 
18333, 18334, 18335, 18336, 18337, 18338, 18339, 18340, 18344, 
18345, 18346, 18347, 18348, 18350, 18351, 18352, 18353, 18355, 
18358, 18359, 18366, 18367, 18373, 18374, 18375, 18376, 18377, 
18378, 18379, 18381, 18382, 18386, 18388, 18389, 18390, 18392, 
18394, 18395, 18396, 18400, 18401, 18402, 18403, 18406, 18407, 
18408, 18409, 18411, 18412, 18413, 18415, 18416, 18417, 18418, 
18421, 18422, 18424, 18425, 18427, 18428, 18429, 18430, 18431, 
18432, 18434, 18436, 18437, 18438, 18439, 18443, 18444, 18445, 
18446, 18447, 18448, 18449, 18450, 18451, 18452, 18453, 18454, 
18455, 18456, 18457, 18458, 18459, 18460, 18461, 18462, 18463, 
18464, 18465, 18466, 18470, 18471, 18472, 18473, 18474, 18477, 
18478, 18479, 18481, 18484, 18485, 18486, 18487, 18490, 18491, 
18493, 18494, 18495, 18498, 18499, 18500, 18501, 18502, 18504, 
18505, 18506, 18507, 18508, 18509, 18511, 18512, 18514, 18515, 
18516, 18517, 18519, 18520, 18521, 18522, 18523, 18527, 18528, 
18529, 18530, 18531, 18533, 18534, 18535, 18536, 18537, 18538, 
18541, 18542, 18543, 18544, 18546, 18549, 18551, 18554, 18555, 
18557, 18558, 18559, 18561, 18563, 18564, 18565, 18566, 18568, 
18569, 18570, 18571, 18572, 18573, 18575, 18576, 18577, 18579, 
18582, 18583, 18585, 18589, 18590, 18591, 18592, 18594, 18596, 
18597, 18598, 18599, 18600, 18603, 18604, 18605, 18606, 18607, 
18610, 18611, 18612, 18613, 18614, 18615, 18617, 18619, 18620, 
18622, 18624, 18625, 18626, 18630, 18631, 18634, 18635, 18636, 
18637, 18638, 18639, 18640, 18641, 18642, 18643, 18644, 18645, 
18646, 18647, 18648, 18649, 18652, 18653, 18654, 18655, 18656, 
18661, 18662, 18663, 18666, 18667, 18668, 18669, 18670, 18671, 
18673, 18674, 18675, 18676, 18677, 18678, 18679, 18680, 18681, 
18682, 18684, 18687, 18688, 18690, 18691, 18694, 18696, 18697, 
18698, 18701, 18702, 18703, 18704, 18705, 18708, 18709, 18712, 
18716, 18717, 18722, 18723, 18724, 18725, 18729, 18730, 18733, 
18736, 18737, 18739, 18740, 18742, 18743, 18745, 18746, 18751, 
18753, 18757, 18758, 18760, 18761, 18763, 18765, 18766, 18767, 
18768, 18771, 18772, 18773, 18774, 18775, 18776, 18778, 18779, 
18780, 18781, 18782, 18785, 18786, 18788, 18789, 18793, 18795, 
18798, 18799, 18800, 18801, 18802, 18803, 18804, 18805, 18806, 
18807, 18808, 18809, 18810, 18813, 18814, 18815, 18817, 18820, 
18821, 18822, 18824, 18827, 18828, 18830, 18831, 18834, 18835, 
18836, 18837, 18838, 18840, 18842, 18843, 18844, 18845, 18846, 
18847, 18848, 18849, 18851, 18852, 18855, 18857, 18858, 18859, 
18863, 18864, 18866, 18868, 18869, 18870, 18871, 18877, 18878, 
18879, 18884, 18886, 18887, 18888, 18890, 18891, 18892, 18893, 
18897, 18898, 18899, 18900, 18904, 18905, 18907, 18911, 18913, 
18914, 18915, 18918, 18919, 18920, 18921, 18926, 18927, 18928, 
18933, 18934, 18935, 18939, 18940, 18941, 18942, 18946), class = "Date"), 
    n = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 78L, 
    1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L,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 4L, 2L, 5L, 2L, 1L, 1L, 2L, 2L, 2L, 
    1L, 1L, 2L, 1L, 4L, 1L, 1L, 4L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 
    1L, 2L, 1L, 2L, 1L, 3L, 2L, 2L, 8L, 1L, 1L, 2L, 1L, 2L, 3L, 
    1L, 1L, 1L, 2L, 3L, 1L, 1L, 2L, 6L, 2L, 1L, 3L, 1L, 1L, 1L, 
    1L, 2L, 8L, 1L, 1L, 1L, 5L, 1L, 2L, 1L, 1L, 2L, 3L, 3L, 4L, 
    2L, 3L, 3L, 1L, 1L, 3L, 2L, 1L, 1L, 11L, 3L, 2L, 2L, 2L, 
    2L, 1L, 3L, 2L, 3L, 7L, 4L, 1L, 3L, 2L, 5L, 14L, 4L, 4L, 
    1L, 3L, 11L, 6L, 3L, 2L, 2L, 5L, 3L, 1L, 2L, 2L, 1L, 3L, 
    1L, 1L, 1L, 2L, 1L, 1L, 1L, 5L, 3L, 1L, 1L, 1L, 1L, 1L, 3L, 
    1L, 1L, 2L, 2L, 3L, 1L, 4L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 
    2L, 1L, 3L, 1L, 1L, 1L, 1L, 3L, 1L, 2L, 3L, 4L, 2L, 1L, 3L, 
    3L, 5L, 1L, 1L, 1L, 2L, 1L, 2L, 1L)), class = c("tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -929L))

How can I solve this problem? I've checked if the date format is correct and it is. The thing is I have done this before, to fill dates. I don't know why I'm getting this error message.

CodePudding user response:

You were close but I think this is what you were after:

dades_aux %>%
  complete(data_minima = seq.Date(min(data_minima), max(data_minima), by="day"))

CodePudding user response:

another solution

dades_aux %>%
  complete(data_minima = full_seq(data_minima, period = 1))
  • Related