i am wondering if anyone knows of any functions/tactics for calculating this problem i have:
so if I have the variable x
x <- c(1,2,3,4,5,6,7,8,9)
dataframe <- data.frame(x)
dataframe$y <- 0
and I want to calculate the sum of the differences between each value and the rest of the values. Then each value in this variable will have a score of the difference. Something along the lines of: y[1]<-sum((x[1]-2) + (x[1]-3) + (x[1]-4)....(x[1]-9))
Something along the lines of this (since in reality I have a big data frame with many conditions i want to run this calculation over)
difference_sum <- 0
for (i in x) {
value_of_interest <- x[i]
difference_sum <- difference_sum + (x[i] - x[i+1])
difference_sum <- difference_sum + (x[i] - x[i+2])
}
#all the way through the end of the list
thanks!