How to use tibble to calculate mean of every 15 rows of a text file in R?

I have a text file (with every minute data) with more than 4000 rows and 19 columns. The file structure is as follows:

Few lines of metadata
Date  Time AirTemp  Pres  Wind ....
2021-03-01 00:00:00 27  1017  10....
2021-03-01 00:01:00.....

I want to calculate mean of every 15 rows for all the columns (e.g. mean of rows 1 to 15, then mean of rows 16-30 and so on..). I want to save it in .csv file. I have used following code in R to calculate 15 rows average for all the columns.

df <- read.table('C:/Users/Alexia/Desktop/Test/Test1.txt', header=TRUE, 
sep = "\t", check.names = FALSE, skip=27)

library(dplyr)

df %>%
 group_by(group = as.integer(gl(n(), 15, n()))) %>%
 summarise_all(funs(mean))

It ran successfully but it is giving me following warnings:

Warning messages:
1: `funs()` was deprecated in dplyr 0.8.0.
ℹ Please use a list of either functions or lambdas:

# Simple named list: list(mean = mean, median = median)
# Auto named with `tibble::lst()`: tibble::lst(mean, median)
# Using lambdas list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated. 
2: There were 2976 warnings in `summarise()`.
The first warning was:
ℹ In argument: `Date/Time = mean(`Date/Time`)`.
ℹ In group 1: `group = 1`.
Caused by warning in `mean.default()`:
! argument is not numeric or logical: returning NA
ℹ Run dplyr::last_dplyr_warnings() to see the 2975 remaining warnings.

As I am new to R, I want to understand that as the warnings mention that funs() was deprecated in dplyr 0.8.0, can I not use it in future? Does it recommend to use tibble to calculate mean? How can I use tibble or any other method to calculate every 15 rows average for all the columns and save it in a csv? Thanks.

As data is huge, I have created a sample file of 4 records. The output of dput(df) is as follows:

structure(list(`Date/Time` = c("2021-03-01T00:00:00", "2021-03- 
01T00:01:00", "2021-03-01T00:02:00", "2021-03-01T00:03:00"), `XY` = 
c(990641, 41, 641, 906), `R1` = c(250, 27, 57, 56), `R2` = c(85, 
84, 89, 64), class = "data.frame", row.names = c(NA, -4))


Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)