R scripts are table calculations. Like all table calculations, this means that you can only utilize fields that are on your view. Also, it's important that you set partitioning and addressing correctly otherwise you may receive unexpected results. Let's adjust the partitioning and addressing from the Exercise – Correlations section and observe the results.
Note in this screenshot that Compute Using is set to Customer ID. This is necessary to correctly calculate the correlation between Sales and Profit:
Adjusting Compute Using to State will result in very different and fairly meaningless results: