The total amount for n rows

I am trying to create a command in R that allows me to create a new vector, where each line is the sum of 25 lines from the previous vector.

I tried to make a function to do this, this allows me to create a result for a single data point.

I will put where I got; I understand that this is probably a pretty simple question, but this is the one I struggled with ... any help would be greatly appreciated;

example<-c(1;200) fun.1<-function(x) {sum(x[1:25])} checklist<-sapply(check,FUN=fun.1) 

Then I am given a vector of length 200, where all values ​​are equal to NA.

Can anyone help at all?

0
source share
1 answer

Your example is a bit noisy (for example, c(1;200) does not make sense, maybe you want 1:200 there, or if you want to have a list of lists, something like rep , no check , it should be example and etc.).

Here is the code that I think you need (as far as I could understand it):

 x <- rep(list(1:200), 5) f <- function(y) {y[1:20]} sapply(x, f) 

Next time, please be more specific, try the code that you send as an example before submitting a question.

+2
source

All Articles