I’m running cor() on a data.framewith all numeric values and I’m getting this as the result:
price exprice...
price 1 NA
exprice NA 1
...
So it’s either 1 or NA for each value in the resulting table. Why are the NAs showing up instead of valid correlations?
The
1s are because everything is perfectly correlated with itself, and theNAs are because there areNAs in your variables.You will have to specify how you want R to compute the correlation when there are missing values, because the default is to only compute a coefficient with complete information.
You can change this behavior with the
useargument tocor, see?corfor details.