I have time-series data at one-minute interval (data frame name is pn.nano). I wish to convert it into 5-minute averaged data. But before averaging, it should be ensured that each 5-minute interval has at least 3 values (i.e. each 5-min interval should have at least 3 minutes of data). Then only averaging should be done otherwise the data should be filtered out.

The data looks as follows. The column names (11.5, 15.4, etc.) are the pollutants whose variation with time is being monitored.

```
nano.pn <- structure(list(datetime = structure(c(1491887640, 1491887700, 
           1491887760, 1491887820, 1491887880, 1491887940, 1491888000, 1491888060, 
           1491888120, 1491888180), tzone = "Asia/Calcutta", class = c("POSIXct", 
           "POSIXt")), `11.5` = c(5938.99, 5530.35, 4825.41, 4439.71, 4357.98, 
           4467.01, 3956.29, 3880.23, 3469.57, 3356.23), `15.4` = c(9594.94, 
           9124.55, 8382.42, 8223.1, 8216.26, 8454.1, 8112.84, 7519.49, 
           7060.94, 7337.3), `20.5` = c(5126.89, 4965.06, 4749.27, 4941.16, 
           5081.44, 5254.23, 5424.79, 4855.33, 4790.21, 5149.6), `27.4` = c(2936.92, 
           2882.55, 2704.88, 2856.22, 2868.12, 2909.07, 3106.77, 2887.35, 
           2802.64, 2853.24), `36.5` = c(1768.23, 1770.75, 1584.26, 1619.82, 
           1558.73, 1610.95, 1587.24, 1557.97, 1481.79, 1323.94)), row.names = c(NA, 
           -10L), class = c("tbl_df", "tbl", "data.frame"))

```

My approach is to use the following code:

```
x <- nano.pn %>% mutate(datetime= floor_date(datetime, unit = "5 mins"))
n <- x %>% group_by(datetime) %>% summarise(countt= n())
n.pn.5min <- x %>% mutate(countt= rep(n$countt,n$countt)) %>% filter(countt>2) %>% 
                   group_by(datetime) %>% summarise_all(mean, na.rm= TRUE)

```

Although this works fine, is there any better approach?