Search code examples
rstandardsstandard-deviation

Standard deviation on a vector of a row of several columns in steps of 10


I want to calculate a standard deviation step by 10 in R; for example

I'm a beginenr using programmation.

Example: I have a vector of :

exemple <- seq (0,100,10) 

If I do sd (exemple) : I have the value of standard deviation but for all values in exemple.

But, how can I do to calculate the standard deviation to this exemple selectionning 10 by 10 steps ?

Can someone help me please ?

for more illustrations : Here is the exemple :

0 10 20 30 40 50 60 70 80 90 etc..

But instead of calculating the standard deviation of all these values, I want to calculate it between 0 and 10, between 10 and 20, between 20 and 30 etc…


Solution

  • example <- seq(0, 100, 10)
    
    for(i in 1:(length(example)-1)){
      print(sd(c(example[i], example[i+1])))
    }