Home > Mobile >  Complete missing hour in dataframe with NA using dplyr in R
Complete missing hour in dataframe with NA using dplyr in R

Time:10-08

I have data like this:

datex <- c("01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","01/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","02/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","03/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","04/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","05/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","06/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","07/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","08/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","09/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","10/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","11/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","12/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","13/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","14/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","15/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","16/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","17/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","18/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","19/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","20/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","21/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","22/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","23/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","24/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","25/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","26/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","27/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","28/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","29/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","30/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","31/07/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","01/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","02/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","03/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","04/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","05/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","06/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","07/08/2021","08/08/2021","08/08/2021","08/08/2021","08/08/2021","08/08/2021","08/08/2021","08/08/2021","08/08/2021","08/08/2021","08/08/2021","08/08/2021","08/08/2021","08/08/2021","08/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","09/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","10/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","11/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","12/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","13/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","14/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","15/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","16/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","17/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","18/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","19/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","20/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","21/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","22/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","23/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","24/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","25/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","26/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","27/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","28/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","29/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","30/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021","31/08/2021")

hourx <- c(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23)

sales <- c(16,9,7,44,63,80,66,98,123,107,57,63,68,134,107,80,62,102,81,71,54,36,21,34,43,59,75,65,52,65,43,34,75,79,114,143,126,107,83,134,88,70,70,69,50,40,23,29,40,57,57,64,72,71,99,136,103,71,121,139,110,121,90,40,50,65,63,52,44,30,20,27,38,57,74,58,69,105,121,142,151,137,27,25,25,40,54,59,42,36,24,15,24,35,56,78,13,14,73,98,37,65,91,48,43,84,137,133,184,176,178,158,157,80,39,30,44,46,56,75,67,63,62,72,123,176,159,142,133,87,47,47,41,54,61,76,60,49,33,20,30,40,53,85,87,87,93,119,81,98,136,129,127,96,129,81,45,59,70,72,57,50,36,23,30,41,54,84,88,10,13,24,84,108,103,53,43,129,145,137,130,113,98,90,69,57,38,28,35,42,47,77,73,56,70,75,120,167,142,55,54,111,120,89,104,77,79,79,75,63,45,32,40,46,63,99,95,89,58,60,112,148,94,100,135,93,75,42,51,51,66,65,50,46,31,20,27,37,55,97,89,88,56,48,35,106,151,139,127,85,30,24,24,39,53,52,40,33,21,12,21,33,54,90,99,59,73,54,96,155,149,126,120,104,68,75,39,55,68,69,50,42,30,19,27,37,57,93,102,80,64,19,57,100,126,97,102,98,136,126,61,59,73,72,58,45,32,22,29,37,49,80,72,22,25,30,68,101,49,37,48,42,70,138,128,126,134,113,97,100,48,21,28,41,45,39,60,75,56,51,37,83,135,131,120,101,89,75,54,60,77,63,55,50,37,25,30,38,33,30,72,97,91,91,104,107,78,129,129,118,103,111,94,56,67,69,55,46,32,21,29,38,59,85,82,78,67,54,46,75,139,128,121,161,176,91,58,58,66,66,62,53,36,20,27,36,59,95,100,92,54,40,101,150,144,125,108,99,70,72,43,38,49,52,41,34,22,14,22,32,59,90,91,87,67,71,65,136,131,124,122,127,100,90,78,60,68,70,74,64,49,33,38,48,70,94,101,92,71,67,62,91,149,147,138,90,134,96,62,36,51,55,61,54,43,33,40,51,77,108,112,93,81,86,94,48,48,54,60,131,137,127,119,93,120,117,103,77,57,27,34,53,60,97,86,81,72,67,104,67,65,53,46,97,134,102,131,154,130,120,144,84,50,27,27,33,28,25,15,12,40,68,60,77,71,84,59,56,57,71,67,125,133,168,188,164,152,197,168,109,103,119,116,114,115,129,153,147,141,132,128,100,75,100,58,67,82,77,77,68,56,45,42,48,64,88,93,88,96,129,81,42,42,112,130,116,86,132,100,45,52,53,56,49,35,25,28,34,54,91,97,98,105,112,106,150,140,132,134,82,100,44,42,56,69,66,54,47,34,23,30,42,57,81,91,85,65,76,57,63,43,108,145,141,135,154,196,181,101,74,59,50,37,25,31,42,61,89,104,100,105,120,153,159,155,148,131,118,71,61,45,56,72,68,58,51,38,29,33,43,60,90,101,95,89,124,94,70,77,71,73,71,64,131,137,111,112,107,125,74,43,23,31,42,31,24,25,91,62,82,100,76,50,47,68,75,55,113,138,132,143,116,97,113,98,72,62,47,65,90,92,88,87,133,163,160,61,142,92,43,40,53,68,62,51,42,30,21,27,38,58,94,45,21,24,57,85,75,53,66,65,135,130,126,120,127,110,99,42,35,24,16,23,34,59,89,94,83,93,130,126,93,129,145,107,104,83,40,41,55,67,64,49,43,30,20,27,38,56,87,86,85,98,98,127,85,59,135,152,133,121,100,92,65,72,70,54,46,33,22,30,40,60,96,103,97,85,61,42,48,96,147,147,141,128,96,103,68,75,66,55,42,31,22,28,38,49,90,91,95,90,129,156,131,148,111,71,86,86,61,45,51,63,57,50,47,36,25,32,37,57,72,94,81,79,110,113,119,121,107,99,92,48,39,58,63,68,58,46,73,32,21,29,75,79,73,84,106,108,83,48,42,42,44,101,127,106,73,79,73,65,53,51,41,25,16,24,126,83,40,28,27,27,35,49,55,47,41,31,24,30,86,90,75,83,102,124,100,44,109,114,107,118,73,62,62,44,53,66,58,50,41,32,25,30,63,76,76,104,106,118,103,53,50,79,129,131,110,51,37,38,50,66,53,49,40,30,20,29,59,54,52,57,90,119,106,52,70,58,45,39,49,126,113,57,79,81,88,58,45,34,27,37,84,86,85,85,112,127,152,134,123,98,77,119,50,52,45,52,60,63,54,49,41,28,21,11,1,2,1,14,66,80,94,65,65,63,75,110,128,132,112,73,65,64,56,50,45,41,33,36,77,88,104,79,80,104,135,139,94,69,51,38,35,37,36,38,49,60,56,58,46,38,31,36,81,87,69,71,86,103,131,124,119,68,62,60,70,37,26,22,29,27,30,35,30,21,13,9,65,87,93,44,58,93,131,126,97,61,61,46,61,53,42,40,56,66,65,44,41,31,23,31,89,97,105,80,104,143,145,136,137,79,31,28,26,23,22,21,37,50,50,38,30,20,12,22,82,88,98,85,105,136,141,130,128,81,80,48,45,44,45,44,58,69,68,53,44,34,24,33,99,113,107,70,118,141,140,146,138,109,108,83,60,58,58,51,67,81,82,67,56,43,28,33,95,114,109,101,120,138,140,34,61,163,152,62,40,44,44,42,57,73,73,54,43,33,22,30,97,122,115,80,104,143,150,163,154,92,47,48,50,47,45,42,57,71,68,55,44,32,22,29,39,87,115,112,80,101,147,87,62,146,144,123,35,26,23,24,39,54,56,42,34,22,13,22,91,112,100,82,100,134,142,145,139,109,74,56,52,45,47,42,47,50,67,79,70,56,44,38,92,111,100,68,98,133,135,141,141,93,88,67,42,42,43,42,58,72,69,56,45,32,21,30,97,117,107,90,105,138,147,157,161,117,64,45,40,41,43,41,55,70,66,54,44,32,21,14,16,71,98,98,52,89,133,72,126,147,145,100,40,38,40,39,54,68,63,54,44,31,21,28,98,112,101,65,117,139,139,141,139,127,112,93,64,60,46,41,51,60,63,58,46,32,23,32,98,111,107,78,121,141,145,97,41,114,140,81,60,31,28,26,41,55,61,45,34,23,15,23,90,109,107,77,115,136,140,143,144,96,63,29,25,23,21,20,35,51,50,38,31,21,13,21,89,104,94,75,113,131,143,152,150,121,92,61,67,32,31,31,46,60,56,46,37,26,17,26,30,7,5,4,5,69,102,97,58,50,85,61,71,91,140,132,122,125,112,94,68,37,26,43)

mydata <- data.frame(datex, hourx, sales)

As we see in mydata, we miss:

  • hourx 10, 11 & 12 on datex 04/07/2021
  • hourx 10 & 11 on datex 31/07/2021
  • hourx 0,1,2,3,4,5,6,7,8 & 9 on datex 08/08/2021

The question, how do we insert all missing hourx into my data which is sales will be filled with NA using dplyr package?. Many Thank You.

CodePudding user response:

We can use complete

library(dplyr)
library(tidyr)
mydata %>% 
    complete(datex, hourx = 0:23)
  • Related