Home > Back-end >  How do I write this mathematical formula using R?
How do I write this mathematical formula using R?

Time:10-29

This is not homework but an exercise on a textbook. I am stuck on how to use seq() and translate the given formula into R.

Given that:

set.seed(50) 
aVector <- sample(0:9999, 100, replace=T) 
bVector <- sample(0:9999, 100, replace=T)

(a) Create the vector (b2 − a1, b3 −a2, ... ,bn − an−1 )

CodePudding user response:

Much easier to demonstrate this on non-gargantuan data.

set.seed(50) 
aVector <- sample(0:9999, 10, replace = TRUE) 
bVector <- sample(0:9999, 10, replace = TRUE)

aVector
#  [1] 1118  862 2929 9590 2754 7047 9211 1295 9233 5082
bVector
#  [1] 1788 5594 7507 4857 7607 6086 3867 9840 5084  473
bVector[-1] - aVector[-length(aVector)]
# [1]  4476  6645  1928 -1983  3332 -3180   629  3789 -8760
  •  Tags:  
  • r
  • Related