0

I am new to R . I have a large dataset with 1-minute resolution for one year . It makes total of 55940 observation all 1 minute apart with dates and times . I want to change it to six minute resolution data. It necessarily means adding first 6 rows then next 6 and so on so forth . Any good solutions ?

Shah
  • 31
  • 5
  • add sample data or head(data) – sai saran Nov 08 '18 at 10:28
  • What is your goal? You want end up with a dataset with less raws? Would you like average your values over each 6 rows interval? Would you like to pickup one row every six? Could this So question be useful? https://stackoverflow.com/questions/23279550/select-every-nth-row-from-dataframe – paoloeusebi Nov 08 '18 at 10:46
  • Search for "rolling sum". – zx8754 Nov 08 '18 at 11:02

2 Answers2

1

You could try something like this:

library(dplyr)

# original df
df <- data.frame(min = 1:60, val = rnorm(60))

# create a grouping variable and add to df
grp <- floor(df$min / 6)
df <- data.frame(grp, df)

# create new df at 6 min level
new.df <- df %>% 
  group_by(grp) %>%
  summarise(new.val = sum(val))
Cleland
  • 349
  • 1
  • 6
1

Another option with a similar approach

library(dplyr)

# original dataframe
n <- 55940
df <- data.frame(id = 1:n , val = rnorm(n))

# new dataframe
df_new <- df %>%
  group_by(cut(df$id, n/6)) %>%
  summarise(new.val = sum(val))
paoloeusebi
  • 1,056
  • 8
  • 19