cor shows only NA or 1 for correlations - Why?

Dave picture Dave · Sep 26, 2010 · Viewed 105.8k times · Source

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?

Answer

dmt picture dmt · Jun 26, 2014

Tell the correlation to ignore the NAs with use argument, e.g.:

cor(data$price, data$exprice, use = "complete.obs")