mean across all columns

Hi,

I am trying to calculate the daily mean of multiple columns using

neeraj[neeraj == 0] <- NA
neeraj$date <- as.POSIXct(as.character(paste(neeraj$date)), format="%m-%d-%Y %H:%M")
neeraj %>% 
  group_by(Datetime = floor_date(date, "day")) %>%    ##### hOURLY MEAN
  summarize_if(is.numeric, mean, na.rm = TRUE) 

But, I am facing some issue like

Error in `summarize_if()`:
! `.funs` must be a one sided formula, a function, or a function name.
Run `rlang::last_error()` to see where the error occurred.

But, if I do the mean of one columns via

neeraj %>% 
  group_by(Datetime = floor_date(date, "day")) %>%    ##### hOURLY MEAN
  summarise(pm = mean(pm2.5, na.rm = TRUE)) 

then it's working.
So, could please let me know how to do the mean across all columns.
The data can be found on

Here is an example of how to do it using the built-in iris data set

library(dplyr)

iris %>% 
    summarise(across(.cols = where(is.numeric),
                     .fns = mean,
                     rm.na = TRUE,
                     .names = "{.col}_mean"))
#>   Sepal.Length_mean Sepal.Width_mean Petal.Length_mean Petal.Width_mean
#> 1          5.843333         3.057333             3.758         1.199333

Created on 2022-03-16 by the reprex package (v2.0.1)

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

Hi,

Initial data is given in hours like

# Groups:   Datetime [275]
   date                pm2.5    no   no2   nox   so2    co    o3 benzene toulene Temp     rh    ws    wd    sr    bp
   <dttm>              <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>   <dbl>   <dbl> <lgl> <dbl> <dbl> <dbl> <dbl> <dbl>
 1 2020-04-01 00:00:00 120.  33.2   140. 102.   13.4  1.99    NA    0.47    0.78 NA     87     0.3  302    6    760 
 2 2020-04-01 01:00:00 104.  33.4   142. 103.   12.5  1.9     NA    0.53    0.65 NA     87.5   0.3  262.   6    760.
 3 2020-04-01 02:00:00  99.5 36.0   139. 103.   14.4  1.87    NA    0.5     0.7  NA     88.8   0.3  288    6    762.
 4 2020-04-01 03:00:00  99.5 41.3   145. 111.   16.0  1.7     NA    0.53    0.6  NA     89.2   0.3  172    6    762 
 5 2020-04-01 04:00:00 108.  47.1   138. 111.   17.2  2.14    NA    1.42    1.97 NA     89.5   0.3   NA    6    763.
 6 2020-04-01 05:00:00 122.  46.1   133. 108.   17.2  2.17    NA    2.05    3.15 NA     90     0.3   NA    6    762.
 7 2020-04-01 06:00:00 118.  41.9   135. 106.   15    2.35    NA    1.8     1.95 NA     88.5   0.3   NA   16.8  760.
 8 2020-04-01 07:00:00 115   30.2   139.  98.7  15.1  2.41    NA    1.67    1.85 NA     84.5   0.3   NA   51.5  756.
 9 2020-04-01 08:00:00 120.  17.9   144.  91.0  16.2  2.29    NA    1.52    1.88 NA     79.8   0.3   NA   93.2  752.

I need the output in daily mean like given below, but for each column

# A tibble: 275 × 2
   Datetime               pm
   <dttm>              <dbl>
 1 2020-04-01 00:00:00  88.1
 2 2020-04-02 00:00:00  65.5
 3 2020-04-03 00:00:00  50.1
 4 2020-04-04 00:00:00  63.8
 5 2020-04-05 00:00:00  70.3
 6 2020-04-06 00:00:00  59.4
 7 2020-04-07 00:00:00  58.0
 8 2020-04-08 00:00:00  67.6
 9 2020-04-09 00:00:00  69.1
10 2020-04-10 00:00:00  83.1

I am able to do it for one column via

neeraj %>% 
  group_by(Datetime = floor_date(date, "day")) %>%    ##### hOURLY MEAN
  summarise(pm = mean(pm2.5, na.rm = TRUE)) 

But, FOR multiple columns I am trying

neeraj %>% 
  group_by(Datetime = floor_date(date, "day")) %>%    ##### hOURLY MEAN
  summarize_if(is.numeric, mean, na.rm = TRUE)

and it's not working and giving an error (previous post).

Have you tried my proposed solution?

neeraj %>% 
  group_by(Datetime = floor_date(date, "day")) %>%
  summarise(across(.cols = where(is.numeric),
                     .fns = mean,
                     rm.na = TRUE,
                     .names = "{.col}_mean"))

As I said, if you need help with your specific data, we need a proper reproducible example, the sample data you are sharing is not on a copy/paste friendly format and it only have records for one day so it is not big enough to illustrate your problem.

In the future, please try to provide a proper reproducible example as explained on the link I gave you before.

Yes, I tried, But I m getting an error from this,

Error in `summarise()`:
! Problem while computing `..1 = across(...)`.
ℹ The error occurred in group 1: Datetime = 2020-04-01.
Caused by error in `across()`:
! Names must be unique.
x These names are duplicated:
  * "pm2.5_mean" at locations 1, 2, 3, 4, 5, etc.
  * "no_mean" at locations 7, 8, 9, 10, 11, etc.
  * "no2_mean" at locations 13, 14, 15, 16, 17, etc.
  * "nox_mean" at locations 19, 20, 21, 22, 23, etc.
  * "so2_mean" at locations 25, 26, 27, 28, 29, etc.
  * ...
Run `rlang::last_error()` to see where the error occurred.

the data would be like this

date	pm2.5	no	no2	nox	so2	co	o3	benzene	toulene	Temp	rh	ws	wd	sr	bp	vws	xylene	at
04-01-2020 0:00	119.5	33.25	140.22	101.62	13.45	1.99	NA	0.47	0.78	NA	87	0.3	302	6	760	-1.08	0	30.73
04-01-2020 1:00	104.5	33.42	142.25	102.83	12.47	1.9	NA	0.53	0.65	NA	87.5	0.3	261.75	6	760.25	-1.18	0	30.9
04-01-2020 2:00	99.5	35.95	138.93	103.12	14.38	1.87	NA	0.5	0.7	NA	88.75	0.3	288	6	761.5	-1.39	0	31.23
04-01-2020 3:00	99.5	41.32	145.05	110.72	16.02	1.7	NA	0.53	0.6	NA	89.25	0.3	172	6	762	-1.62	0	31.48
04-01-2020 4:00	108.5	47.08	137.52	111.45	17.2	2.14	NA	1.42	1.97	NA	89.5	0.3	NA	6	762.75	-1.48	0	31.55
04-01-2020 5:00	121.75	46.1	133.05	108.25	17.15	2.17	NA	2.05	3.15	NA	90	0.3	NA	6	761.75	-1.52	0	31.77
04-01-2020 6:00	118.5	41.9	134.78	105.75	15	2.35	NA	1.8	1.95	NA	88.5	0.3	NA	16.75	760.25	-1.42	0	31.1
04-01-2020 7:00	115	30.2	139.35	98.67	15.07	2.41	NA	1.67	1.85	NA	84.5	0.3	NA	51.5	756.5	-1.49	0	29.82
04-01-2020 8:00	119.75	17.9	143.6	90.95	16.15	2.29	NA	1.52	1.88	NA	79.75	0.3	NA	93.25	752.5	-1.81	0	28.35
04-01-2020 9:00	87.25	9.17	146.75	85.53	16.33	2.17	NA	1.2	1.23	NA	77.5	0.3	NA	131.5	750	-1.88	0	27.4
04-01-2020 10:00	56.25	9.53	142.52	83.53	15.52	2.17	NA	1.05	1.3	NA	75.5	0.3	NA	160.5	749	-1.78	0	26.82
04-01-2020 11:00	57.5	8.75	139.95	81.55	14.48	1.93	NA	0.83	0.93	NA	75	0.3	NA	179	748.25	-1.97	0	26.52
04-01-2020 12:00	45.25	4.1	128.97	71	14.32	1.06	NA	0.5	0.53	NA	74	0.3	NA	181.5	748	-1.77	0	26.25
04-01-2020 13:00	31.75	8.57	127.55	74.83	14.02	0.95	NA	0.28	0	NA	73	0.3	NA	161.75	747.5	-1.84	0	25.88
04-01-2020 14:00	36.25	8.03	130.25	75.8	14.7	0.9	NA	0.23	0	NA	73	0.3	NA	136.75	747.25	-1.8	0	25.88
04-01-2020 15:00	41.75	6.62	133.5	76.38	15.18	0.9	NA	0.2	0	NA	73	0.3	NA	94.25	747	-2	0	25.8
04-01-2020 16:00	39.75	6.78	138.9	79.38	13.62	0.9	NA	0.28	0	NA	73.5	0.3	NA	48.25	747.75	-2.12	0	26.05
04-01-2020 17:00	50	7.55	139.95	80.57	12.6	1.02	NA	0.3	0	NA	75.5	0.3	NA	12.5	748.5	-2.04	0	26.77
04-01-2020 18:00	66.75	8.03	125.35	73.17	13.12	1.12	NA	0.28	0.25	NA	78	0.3	NA	6	750	-1.77	0	27.65
04-01-2020 19:00	95.25	11.4	95.42	60.05	14.2	1.77	NA	0.53	0.6	NA	80	0.3	NA	6	751.75	-1.46	0	28.38
04-01-2020 20:00	156.5	18.35	128.02	83.03	14.12	2.19	NA	1.38	1.53	NA	81.5	0.3	NA	6	753	-1.41	0	28.82
04-01-2020 21:00	128.75	20.85	137.4	90.03	14.62	2.29	NA	1.68	1.88	NA	82.75	0.3	NA	6	754	-1.31	0	29.25
04-01-2020 22:00	117.25	20.65	138.53	90.5	14.85	2.19	NA	1.55	1.9	NA	83.25	0.3	267.5	6	754.75	-1.17	0	29.48
04-01-2020 23:00	96.75	23.12	133	89.58	14.32	1.99	NA	1.22	1.57	NA	84	0.3	305.75	6	755.25	-1.08	0	29.68
04-02-2020 0:00	77.5	25.88	136.05	93.38	17.02	1.72	NA	1.17	1.67	NA	85	0.3	246	6	756	-1.12	0	29.92
04-02-2020 1:00	75.25	28	134.47	94.25	18.8	1.71	NA	1.23	1.8	NA	85.75	0.3	NA	6	757.5	-1.57	0	30.25
04-02-2020 2:00	72	29.18	132.15	93.98	18.93	1.64	NA	1.2	1.8	NA	86	0.3	NA	6	758	-1.53	0	30.45
04-02-2020 3:00	67.25	29.3	132.12	94.12	18.15	1.56	NA	1.05	1.52	NA	87	0.3	326	6	758.75	-1.22	0	30.65
04-02-2020 4:00	59.75	28.17	122.27	87.95	17.8	1.46	NA	0.62	0.92	NA	87	0.3	NA	6	759	-1.53	0	30.67
04-02-2020 5:00	56.75	29.07	124.47	89.88	16.05	1.44	NA	0.38	0.55	NA	87	0.3	NA	6	759.5	-1.49	0	30.68
04-02-2020 6:00	73	26.68	127.07	89.3	17.62	1.62	NA	0.35	0.55	NA	86.5	0.3	NA	15.25	760.25	-1.4	0	30.55
04-02-2020 7:00	92.75	22.83	130.3	87.88	17.07	1.66	NA	0.35	0.35	NA	83.5	0.3	NA	49.5	756.75	-1.46	0	29.43
04-02-2020 8:00	105.5	14.85	132.4	82.5	15.88	1.55	NA	0.4	0.47	NA	79.25	0.3	NA	92	753.75	-1.45	0	28.07
04-02-2020 9:00	98.25	10.23	133.22	79.17	15.97	1.48	NA	0.43	0.47	NA	77.5	0.3	NA	130	752.75	-1.34	0	27.45
04-02-2020 10:00	80.25	8.22	124.78	73.05	12.7	1.23	NA	0.35	0	NA	74.75	0.3	NA	160.75	749.75	-1.54	0	26.42
04-02-2020 11:00	48.75	9.6	130.5	77.22	10.45	1.07	NA	0.3	0	NA	72.25	0.3	NA	174.5	748.25	-2.04	0	25.72
04-02-2020 12:00	47	12.65	138.97	84.2	15.1	1.75	NA	0.38	0.32	NA	72	0.3	NA	176	748	-2.19	0	25.52
04-02-2020 13:00	58.5	7.6	136.68	78.88	16.93	2.02	NA	0.55	0.88	NA	72	0.3	NA	155	747.5	-2.09	0	25.5
04-02-2020 14:00	44.5	7.82	135	78.2	15.55	2.05	NA	0.47	0.83	NA	72	0.3	NA	131.5	748	-2.12	0	25.62
04-02-2020 15:00	35.5	9.02	132.7	77.93	14.38	2.04	NA	0.38	0.47	NA	72.25	0.3	NA	90.25	748	-2.07	0	25.72
04-02-2020 16:00	40.5	9.38	91.1	56.08	15.57	2.1	NA	0.38	0.42	NA	73.5	0.3	NA	43.5	748.75	-2.13	0	26.1
04-02-2020 17:00	46.75	18.12	44.33	38.33	15.38	1.82	NA	0.5	0.6	NA	75.5	0.3	NA	11.75	749.75	-2.1	0	26.8
04-02-2020 18:00	59.75	14	61.97	34.6	14.57	2.07	NA	1.2	1.8	NA	77.75	0.3	NA	6	751	-1.96	0	27.52
04-02-2020 19:00	56.5	3.1	105.35	56.97	15.52	2.07	NA	1.48	2.17	NA	79.5	0.3	NA	6	752.5	-1.9	0	28.05
04-02-2020 20:00	58.5	5.28	115.9	65.92	17.33	1.26	NA	0.93	1.18	NA	81	0.3	280	6	753.75	-1.52	0	28.65
04-02-2020 21:00	60.75	13.38	126.2	78.02	18.05	1.5	NA	0.35	0.28	NA	82	0.3	264	6	753.75	-1.65	0	28.98
04-02-2020 22:00	68.25	15.8	130.38	82.2	13.1	1.63	NA	0.32	0	NA	82	0.3	NA	6	753	-1.85	0	29.02
04-02-2020 23:00	88.25	14.85	132.95	82.78	11.22	1.6	NA	0.23	0	NA	83	0.3	NA	6	754	-2.12	0	29.32
04-03-2020 0:00	99.5	13.92	134.08	82.6	13.22	1.31	NA	0.3	0	NA	83.25	0.3	NA	6	753.75	-2.02	0	29.45
04-03-2020 1:00	88.75	13.77	136.05	83.55	13.7	1.61	NA	0.3	0	NA	84	0.3	NA	6	754	-2.08	0	29.62
04-03-2020 2:00	69.75	11.95	133.15	80.53	12.72	1.61	NA	0.2	0	NA	85	0.3	NA	6	755	-2.13	0	30
04-03-2020 3:00	65.25	11.6	132.95	80.12	11.43	1.33	NA	0.23	0	NA	86	0.3	NA	6	755.25	-2.14	0	30.3
04-03-2020 4:00	55	16.07	133.38	83.97	15.68	1.63	NA	0.35	0.17	NA	87	0.3	NA	6	756	-2.13	0	30.6
04-03-2020 5:00	57.25	12.78	126.78	77.85	18.15	2.12	NA	0.88	0.93	NA	87	0.3	NA	6	756	-2.17	0	30.65
04-03-2020 6:00	53.25	7.7	127.05	73.82	17.35	2.15	NA	0.8	0.95	NA	85.5	0.3	NA	19	755	-2.12	0	30.05
04-03-2020 7:00	48.5	13.22	128.55	79.12	16.75	2.19	NA	0.8	0.95	NA	82.5	0.3	NA	60	753	-2.04	0	29.1
04-03-2020 8:00	48.75	7.9	134.62	78.05	18.05	2.17	NA	0.72	1.02	NA	79.75	0.3	NA	105.25	750.75	-1.92	0	28.1
04-03-2020 9:00	44.25	11.18	133.2	79.95	17.38	2.15	NA	0.65	0.88	NA	77.5	0.3	NA	144	749	-2.02	0	27.48
04-03-2020 10:00	41.5	8.85	137.18	80.15	15.93	2.1	NA	0.57	0.7	NA	76.5	0.3	NA	175	748	-1.94	0	27.03
04-03-2020 11:00	38.25	10.58	132.65	79.12	15.15	2.03	NA	0.47	0.83	NA	75.25	0.3	NA	190.75	746	-2.13	0	26.73
04-03-2020 12:00	30.75	3.4	125.78	69.65	14.43	1.36	NA	0.35	0.65	NA	75	0.3	NA	190.5	746	-2	0	26.55
04-03-2020 13:00	24.75	9.4	125.7	74.5	14.3	1.23	NA	0.08	0	NA	74.25	0.3	NA	167.5	745.75	-2.03	0	26.3
04-03-2020 14:00	26.25	6.9	129.1	74.3	12.5	1.2	NA	0	0	NA	74.5	0.3	NA	142.5	745.5	-2.09	0	26.4
04-03-2020 15:00	23.75	7.77	129.57	75.25	12.93	1.19	NA	0	0	NA	75	0.3	NA	100.25	745.25	-2.14	0	26.5
04-03-2020 16:00	21.5	7.72	131.5	76.25	11.72	1.21	NA	0	0	NA	75.25	0.3	NA	56.75	745.75	-2.07	0	26.73
04-03-2020 17:00	18.75	9.03	137.15	80.28	12.27	1.39	NA	0	0	NA	77.5	0.3	NA	15.5	746.5	-2.08	0	27.4
04-03-2020 18:00	25.75	9.3	139.78	81.92	14.85	1.51	NA	0	0	NA	80	0.3	NA	6	747.75	-2.15	0	28.33
04-03-2020 19:00	33.5	9.9	147.22	86.35	17.02	1.82	NA	0.15	0	NA	81.5	0.3	NA	6	748	-1.95	0	28.82
04-03-2020 20:00	47.25	15.72	157.35	96.47	17.58	1.8	NA	0.25	0.25	NA	82.25	0.3	NA	6	748.75	-1.65	0	29.1
04-03-2020 21:00	72.5	16.18	150.07	93.03	17	2.54	NA	0.95	1.18	NA	84	0.3	NA	6	751	-1.38	0	29.7
04-03-2020 22:00	89.5	18.23	150.77	95	14.15	2.36	NA	1.02	1	NA	85	0.3	355	6	751.75	-1.44	0	29.95
04-03-2020 23:00	78	18.05	151.5	95.28	12.65	2.18	NA	0.78	0.83	NA	85	0.3	NA	6	751	-1.7	0	29.9

this is not an appropriate way to share example data.
please reread the guide you were linked to, pay particular attention for the key word 'dput'

Even if I make the extra effort of reading the sample data from what you have posted into a copy/paste friendly version, your problem is not reproducible with the information you are providing, see this reproducible example:

library(dplyr)
library(lubridate)

# Sample data on a copy/paste friendly format
sample_data <- data.frame(
  stringsAsFactors = FALSE,
              date = c("04-01-2020 0:00",
                       "04-01-2020 1:00","04-01-2020 2:00","04-01-2020 3:00",
                       "04-01-2020 4:00","04-01-2020 5:00","04-01-2020 6:00",
                       "04-01-2020 7:00","04-01-2020 8:00","04-01-2020 9:00",
                       "04-01-2020 10:00","04-01-2020 11:00","04-01-2020 12:00",
                       "04-01-2020 13:00","04-01-2020 14:00","04-01-2020 15:00",
                       "04-01-2020 16:00","04-01-2020 17:00","04-01-2020 18:00",
                       "04-01-2020 19:00","04-01-2020 20:00","04-01-2020 21:00",
                       "04-01-2020 22:00","04-01-2020 23:00","04-02-2020 0:00",
                       "04-02-2020 1:00","04-02-2020 2:00","04-02-2020 3:00",
                       "04-02-2020 4:00","04-02-2020 5:00","04-02-2020 6:00",
                       "04-02-2020 7:00","04-02-2020 8:00","04-02-2020 9:00",
                       "04-02-2020 10:00","04-02-2020 11:00",
                       "04-02-2020 12:00","04-02-2020 13:00","04-02-2020 14:00",
                       "04-02-2020 15:00","04-02-2020 16:00","04-02-2020 17:00",
                       "04-02-2020 18:00","04-02-2020 19:00","04-02-2020 20:00",
                       "04-02-2020 21:00","04-02-2020 22:00","04-02-2020 23:00",
                       "04-03-2020 0:00","04-03-2020 1:00","04-03-2020 2:00",
                       "04-03-2020 3:00","04-03-2020 4:00","04-03-2020 5:00",
                       "04-03-2020 6:00","04-03-2020 7:00","04-03-2020 8:00",
                       "04-03-2020 9:00","04-03-2020 10:00","04-03-2020 11:00",
                       "04-03-2020 12:00","04-03-2020 13:00","04-03-2020 14:00",
                       "04-03-2020 15:00","04-03-2020 16:00",
                       "04-03-2020 17:00","04-03-2020 18:00","04-03-2020 19:00",
                       "04-03-2020 20:00","04-03-2020 21:00","04-03-2020 22:00",
                       "04-03-2020 23:00"),
             pm2.5 = c(119.5,104.5,99.5,99.5,108.5,
                       121.75,118.5,115,119.75,87.25,56.25,57.5,45.25,
                       31.75,36.25,41.75,39.75,50,66.75,95.25,156.5,
                       128.75,117.25,96.75,77.5,75.25,72,67.25,59.75,56.75,
                       73,92.75,105.5,98.25,80.25,48.75,47,58.5,44.5,
                       35.5,40.5,46.75,59.75,56.5,58.5,60.75,68.25,88.25,
                       99.5,88.75,69.75,65.25,55,57.25,53.25,48.5,48.75,
                       44.25,41.5,38.25,30.75,24.75,26.25,23.75,21.5,
                       18.75,25.75,33.5,47.25,72.5,89.5,78),
                no = c(33.25,33.42,35.95,41.32,
                       47.08,46.1,41.9,30.2,17.9,9.17,9.53,8.75,4.1,8.57,
                       8.03,6.62,6.78,7.55,8.03,11.4,18.35,20.85,20.65,
                       23.12,25.88,28,29.18,29.3,28.17,29.07,26.68,22.83,
                       14.85,10.23,8.22,9.6,12.65,7.6,7.82,9.02,9.38,
                       18.12,14,3.1,5.28,13.38,15.8,14.85,13.92,13.77,
                       11.95,11.6,16.07,12.78,7.7,13.22,7.9,11.18,8.85,
                       10.58,3.4,9.4,6.9,7.77,7.72,9.03,9.3,9.9,15.72,
                       16.18,18.23,18.05),
               no2 = c(140.22,142.25,138.93,145.05,
                       137.52,133.05,134.78,139.35,143.6,146.75,142.52,
                       139.95,128.97,127.55,130.25,133.5,138.9,139.95,
                       125.35,95.42,128.02,137.4,138.53,133,136.05,134.47,
                       132.15,132.12,122.27,124.47,127.07,130.3,132.4,
                       133.22,124.78,130.5,138.97,136.68,135,132.7,91.1,44.33,
                       61.97,105.35,115.9,126.2,130.38,132.95,134.08,
                       136.05,133.15,132.95,133.38,126.78,127.05,128.55,
                       134.62,133.2,137.18,132.65,125.78,125.7,129.1,129.57,
                       131.5,137.15,139.78,147.22,157.35,150.07,150.77,
                       151.5),
               nox = c(101.62,102.83,103.12,110.72,
                       111.45,108.25,105.75,98.67,90.95,85.53,83.53,
                       81.55,71,74.83,75.8,76.38,79.38,80.57,73.17,60.05,
                       83.03,90.03,90.5,89.58,93.38,94.25,93.98,94.12,
                       87.95,89.88,89.3,87.88,82.5,79.17,73.05,77.22,84.2,
                       78.88,78.2,77.93,56.08,38.33,34.6,56.97,65.92,
                       78.02,82.2,82.78,82.6,83.55,80.53,80.12,83.97,77.85,
                       73.82,79.12,78.05,79.95,80.15,79.12,69.65,74.5,
                       74.3,75.25,76.25,80.28,81.92,86.35,96.47,93.03,95,
                       95.28),
               so2 = c(13.45,12.47,14.38,16.02,
                       17.2,17.15,15,15.07,16.15,16.33,15.52,14.48,14.32,
                       14.02,14.7,15.18,13.62,12.6,13.12,14.2,14.12,14.62,
                       14.85,14.32,17.02,18.8,18.93,18.15,17.8,16.05,
                       17.62,17.07,15.88,15.97,12.7,10.45,15.1,16.93,
                       15.55,14.38,15.57,15.38,14.57,15.52,17.33,18.05,13.1,
                       11.22,13.22,13.7,12.72,11.43,15.68,18.15,17.35,
                       16.75,18.05,17.38,15.93,15.15,14.43,14.3,12.5,
                       12.93,11.72,12.27,14.85,17.02,17.58,17,14.15,12.65),
                co = c(1.99,1.9,1.87,1.7,2.14,
                       2.17,2.35,2.41,2.29,2.17,2.17,1.93,1.06,0.95,0.9,
                       0.9,0.9,1.02,1.12,1.77,2.19,2.29,2.19,1.99,1.72,
                       1.71,1.64,1.56,1.46,1.44,1.62,1.66,1.55,1.48,
                       1.23,1.07,1.75,2.02,2.05,2.04,2.1,1.82,2.07,2.07,
                       1.26,1.5,1.63,1.6,1.31,1.61,1.61,1.33,1.63,2.12,
                       2.15,2.19,2.17,2.15,2.1,2.03,1.36,1.23,1.2,1.19,
                       1.21,1.39,1.51,1.82,1.8,2.54,2.36,2.18),
                o3 = c(NA,NA,NA,NA,NA,NA,NA,NA,
                       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,
                       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,
                       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,
                       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,
                       NA,NA,NA,NA,NA,NA,NA),
           benzene = c(0.47,0.53,0.5,0.53,1.42,
                       2.05,1.8,1.67,1.52,1.2,1.05,0.83,0.5,0.28,0.23,
                       0.2,0.28,0.3,0.28,0.53,1.38,1.68,1.55,1.22,1.17,
                       1.23,1.2,1.05,0.62,0.38,0.35,0.35,0.4,0.43,0.35,
                       0.3,0.38,0.55,0.47,0.38,0.38,0.5,1.2,1.48,0.93,
                       0.35,0.32,0.23,0.3,0.3,0.2,0.23,0.35,0.88,0.8,
                       0.8,0.72,0.65,0.57,0.47,0.35,0.08,0,0,0,0,0,
                       0.15,0.25,0.95,1.02,0.78),
           toulene = c(0.78,0.65,0.7,0.6,1.97,
                       3.15,1.95,1.85,1.88,1.23,1.3,0.93,0.53,0,0,0,0,0,
                       0.25,0.6,1.53,1.88,1.9,1.57,1.67,1.8,1.8,1.52,
                       0.92,0.55,0.55,0.35,0.47,0.47,0,0,0.32,0.88,
                       0.83,0.47,0.42,0.6,1.8,2.17,1.18,0.28,0,0,0,0,0,
                       0,0.17,0.93,0.95,0.95,1.02,0.88,0.7,0.83,0.65,
                       0,0,0,0,0,0,0,0.25,1.18,1,0.83),
              Temp = c(NA,NA,NA,NA,NA,NA,NA,NA,
                       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,
                       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,
                       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,
                       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,
                       NA,NA,NA,NA,NA,NA,NA),
                rh = c(87,87.5,88.75,89.25,89.5,
                       90,88.5,84.5,79.75,77.5,75.5,75,74,73,73,73,
                       73.5,75.5,78,80,81.5,82.75,83.25,84,85,85.75,86,
                       87,87,87,86.5,83.5,79.25,77.5,74.75,72.25,72,72,
                       72,72.25,73.5,75.5,77.75,79.5,81,82,82,83,
                       83.25,84,85,86,87,87,85.5,82.5,79.75,77.5,76.5,
                       75.25,75,74.25,74.5,75,75.25,77.5,80,81.5,82.25,84,
                       85,85),
                ws = c(0.3,0.3,0.3,0.3,0.3,0.3,
                       0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,
                       0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,
                       0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,
                       0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,
                       0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,
                       0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3,0.3),
                wd = c(302,261.75,288,172,NA,NA,
                       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,
                       NA,NA,267.5,305.75,246,NA,NA,326,NA,NA,NA,NA,
                       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,280,264,
                       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,
                       NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,355,NA),
                sr = c(6,6,6,6,6,6,16.75,51.5,
                       93.25,131.5,160.5,179,181.5,161.75,136.75,94.25,
                       48.25,12.5,6,6,6,6,6,6,6,6,6,6,6,6,15.25,
                       49.5,92,130,160.75,174.5,176,155,131.5,90.25,43.5,
                       11.75,6,6,6,6,6,6,6,6,6,6,6,6,19,60,
                       105.25,144,175,190.75,190.5,167.5,142.5,100.25,56.75,
                       15.5,6,6,6,6,6,6),
                bp = c(760,760.25,761.5,762,762.75,
                       761.75,760.25,756.5,752.5,750,749,748.25,748,
                       747.5,747.25,747,747.75,748.5,750,751.75,753,754,
                       754.75,755.25,756,757.5,758,758.75,759,759.5,
                       760.25,756.75,753.75,752.75,749.75,748.25,748,747.5,
                       748,748,748.75,749.75,751,752.5,753.75,753.75,753,
                       754,753.75,754,755,755.25,756,756,755,753,750.75,
                       749,748,746,746,745.75,745.5,745.25,745.75,
                       746.5,747.75,748,748.75,751,751.75,751),
               vws = c(-1.08,-1.18,-1.39,-1.62,
                       -1.48,-1.52,-1.42,-1.49,-1.81,-1.88,-1.78,-1.97,
                       -1.77,-1.84,-1.8,-2,-2.12,-2.04,-1.77,-1.46,-1.41,
                       -1.31,-1.17,-1.08,-1.12,-1.57,-1.53,-1.22,-1.53,
                       -1.49,-1.4,-1.46,-1.45,-1.34,-1.54,-2.04,-2.19,-2.09,
                       -2.12,-2.07,-2.13,-2.1,-1.96,-1.9,-1.52,-1.65,
                       -1.85,-2.12,-2.02,-2.08,-2.13,-2.14,-2.13,-2.17,
                       -2.12,-2.04,-1.92,-2.02,-1.94,-2.13,-2,-2.03,-2.09,
                       -2.14,-2.07,-2.08,-2.15,-1.95,-1.65,-1.38,-1.44,
                       -1.7),
            xylene = c(0L,0L,0L,0L,0L,0L,0L,0L,
                       0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,
                       0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,
                       0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,
                       0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,
                       0L,0L,0L,0L,0L,0L,0L),
                at = c(30.73,30.9,31.23,31.48,
                       31.55,31.77,31.1,29.82,28.35,27.4,26.82,26.52,26.25,
                       25.88,25.88,25.8,26.05,26.77,27.65,28.38,28.82,
                       29.25,29.48,29.68,29.92,30.25,30.45,30.65,30.67,
                       30.68,30.55,29.43,28.07,27.45,26.42,25.72,25.52,25.5,
                       25.62,25.72,26.1,26.8,27.52,28.05,28.65,28.98,
                       29.02,29.32,29.45,29.62,30,30.3,30.6,30.65,30.05,
                       29.1,28.1,27.48,27.03,26.73,26.55,26.3,26.4,26.5,
                       26.73,27.4,28.33,28.82,29.1,29.7,29.95,29.9)
)

# Relevant code
sample_data %>% 
    mutate(date = mdy_hms(date)) %>% 
    group_by(Datetime = floor_date(date, "day")) %>%
    summarise(across(.cols = where(is.numeric),
                     .fns = mean,
                     rm.na = TRUE,
                     .names = "{.col}_mean"))
#> # A tibble: 3 × 17
#>   Datetime            pm2.5_mean no_mean no2_mean nox_mean so2_mean co_mean
#>   <dttm>                   <dbl>   <dbl>    <dbl>    <dbl>    <dbl>   <dbl>
#> 1 2020-04-01 00:00:00       88.1    20.8     135.     88.7     14.7    1.77
#> 2 2020-04-02 00:00:00       65.5    16.4     121.     77.4     15.8    1.67
#> 3 2020-04-03 00:00:00       50.1    11.3     136.     81.5     14.9    1.76
#> # … with 10 more variables: benzene_mean <dbl>, toulene_mean <dbl>,
#> #   rh_mean <dbl>, ws_mean <dbl>, wd_mean <dbl>, sr_mean <dbl>, bp_mean <dbl>,
#> #   vws_mean <dbl>, xylene_mean <dbl>, at_mean <dbl>

Created on 2022-03-17 by the reprex package (v2.0.1)

In order to help you we need to be able to reproduce your problem, that is why we ask you to provide a reproducible example as explained on the reprex guide I linked for you before.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.