how find the mean and maximum difference between elements of the vector (numbers) using loops in r:
num <- sample(1:1000,50,replace = TRUE)
count <- 0
for (i in 1:length(num)) {
if(i%%4==0){
count <- count+1
numbers <- c(num[num%%4==0])
}
}
print(count)
for example : numbers <- c(700, 748, 364, 288, 896, 960, 624, 712, 340, 564, 828, 68, 948, 524)
without using loops:
diff(numbers) [1] 48 -384 -76 608 64 -336 88 -372 224 264 -760 880 -424
max(diff(numbers)) [1] 880
I want the same solution using loops