Create the data with the planned missing data.
library(tidyverse)
adverts <- c(5, 4, 4, 6, 8)
packetsNA <- c(8, 9, 10, NA, 15)
age <- c(5, 12, 16, 9, 14)
Create the dataframe and convert to tibble format.
advertNA <- as.tibble(data.frame(adverts, packetsNA, age))
advertNA
## # A tibble: 5 x 3
## adverts packetsNA age
## <dbl> <dbl> <dbl>
## 1 5. 8. 5.
## 2 4. 9. 12.
## 3 4. 10. 16.
## 4 6. NA 9.
## 5 8. 15. 14.
cor(advertNA, use = "everything", method = "pearson")
## adverts packetsNA age
## adverts 1.00000000 NA 0.02072962
## packetsNA NA 1 NA
## age 0.02072962 NA 1.00000000
What happened?
cor(advertNA, use = "all.obs", method = "pearson")
Error in cor(advertNA, use = "all.obs", method = "pearson") :
missing observations in cov/cor
What happened?:
cor(advertNA, use = "complete.obs", method = "pearson")
## adverts packetsNA age
## adverts 1.00000000 0.8778665 0.08276409
## packetsNA 0.87786648 1.0000000 0.54869466
## age 0.08276409 0.5486947 1.00000000
What happened?:
cor(advertNA, use = "pairwise.complete.obs", method = "pearson")
## adverts packetsNA age
## adverts 1.00000000 0.8778665 0.02072962
## packetsNA 0.87786648 1.0000000 0.54869466
## age 0.02072962 0.5486947 1.00000000
What happened?:
Complete the Table
Packets and Advertisements | Packets and Age | Age and Advertisement | |
---|---|---|---|
everything | |||
all.obs | |||
complete.obs | |||
pairwise.complete.obs |