Adding Rows in R for large dataset

Multi tool use
up vote
1
down vote
favorite
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 ?
r
New contributor
Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
1
down vote
favorite
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 ?
r
New contributor
Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add sample data or head(data)
– sai saran
Nov 8 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? stackoverflow.com/questions/23279550/…
– paoloeusebi
Nov 8 at 10:46
Search for "rolling sum".
– zx8754
Nov 8 at 11:02
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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 ?
r
New contributor
Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
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 ?
r
r
New contributor
Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 8 at 10:26
Shah
61
61
New contributor
Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add sample data or head(data)
– sai saran
Nov 8 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? stackoverflow.com/questions/23279550/…
– paoloeusebi
Nov 8 at 10:46
Search for "rolling sum".
– zx8754
Nov 8 at 11:02
add a comment |
add sample data or head(data)
– sai saran
Nov 8 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? stackoverflow.com/questions/23279550/…
– paoloeusebi
Nov 8 at 10:46
Search for "rolling sum".
– zx8754
Nov 8 at 11:02
add sample data or head(data)
– sai saran
Nov 8 at 10:28
add sample data or head(data)
– sai saran
Nov 8 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? stackoverflow.com/questions/23279550/…
– paoloeusebi
Nov 8 at 10:46
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? stackoverflow.com/questions/23279550/…
– paoloeusebi
Nov 8 at 10:46
Search for "rolling sum".
– zx8754
Nov 8 at 11:02
Search for "rolling sum".
– zx8754
Nov 8 at 11:02
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
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))
add a comment |
up vote
1
down vote
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))
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
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))
add a comment |
up vote
1
down vote
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))
add a comment |
up vote
1
down vote
up vote
1
down vote
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))
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))
answered Nov 8 at 10:49
Cleland
1356
1356
add a comment |
add a comment |
up vote
1
down vote
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))
add a comment |
up vote
1
down vote
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))
add a comment |
up vote
1
down vote
up vote
1
down vote
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))
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))
answered Nov 8 at 11:11


paoloeusebi
36119
36119
add a comment |
add a comment |
Shah is a new contributor. Be nice, and check out our Code of Conduct.
Shah is a new contributor. Be nice, and check out our Code of Conduct.
Shah is a new contributor. Be nice, and check out our Code of Conduct.
Shah is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205808%2fadding-rows-in-r-for-large-dataset%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
puJ2N1yK6KMZD
add sample data or head(data)
– sai saran
Nov 8 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? stackoverflow.com/questions/23279550/…
– paoloeusebi
Nov 8 at 10:46
Search for "rolling sum".
– zx8754
Nov 8 at 11:02