In my masters program I am trying to implement a decission tree. Therefore I at some point have a vector of sorted and unique values of all variable. e.g.
sorted_unique <- c(1, 3, 5, 7)
now in the next step I am looking for all splitting points - I want to obtain the mean value between all values in the original vector.
splits <- double(length(sorted_unique) - 1)
for (i in 1:length(splits)) {
splits[i] <- mean(sorted_unique[i:(i+1)])
}
this indeed yields the desired
> splits
[1] 2 4 6
however since I have to use this procedure a lot of times, it is very interesting to me, if there is a more efficient way to implement this.
Kind regards