Write code to calculate correlations between two variables, where only certain data are used, based on initial heading and position.