Removing missing data in R

I was playing around with the Latitude and Longitude of hospitals in the UK. When I went to try correlation I got NA because of missing data.

cor(hosp$Latitude,hosp$Longitude)
[1] NA

To get round this I created a new variable.

hosp1 <- na.omit(hosp)

This basically omits all NA (missing values). So use the simple function na.omit to create a new dataset without missing data. This excludes any row that has missing data for ANY value.

Then doing this again

cor(hosp1$Latitude,hosp1$Longitude)
[1] -0.1113144

This indicates very weak negative correlation. So as Latitude increase Longitude decreases slightly. But there is no strong connection.

Published
Categorised as Data, R