I'm trying to subset some values with the specific difference in a vector. In the followed the vector, I wanna separate a vector into several ones with specific difference of 1. For example, A problem
a <- c(1, 1.2, 1.6, 2, 2.2, 2.6, 3, 3.2, 3.6, 4, 4.2, 4.6, 5, 5.2, 5.6, 6, 7, 8, 9, 10)
As a result,
b <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
c <- c(1.2, 2.2, 3.2, 4.2, 5.2)
d <- c(1.6, 2.6, 3.6, 4.6, 5.6)
I tried to code a For loop, but I think it's not efficient and there is the better method for solving this problem.