0

I am trying to make a correlation matrix with all these variables but when I get the table I only get "?" as a result. I am not sure why maybe because the variables I use have missing values?

library(corrplot)
v <- finaliniai %>% select(berd_mio_eur, RRDIN_by_TOT_TURN_PC, INNO.y, uibepart, uibedvaintrca, ENTRP_EDU_PC, RRDEX_BY_TOT_TURN_PC, avg_prsnnl_costs_ths_eur)
v.cor = cor(v)
corrplot(v.cor)
  • 2
    "maybe because the variables I use have missing values?" Probably, yes (you provided no data). NA's are represented as ? into `corrplot`. You can pass `cor(v, na.rm = TRUE)` argument to remove missing values and check your assumption. – Gabriel M. Silva Jul 30 '19 at 19:47
  • 1
    When I apply it to the `mtcars` data as `v <- mtcars %>% select(mpg, wt, disp) ;v.cor = cor(v); corrplot(v.cor)` it is working well. Please check your data set. – maydin Jul 30 '19 at 19:51
  • @GabrielSilva Yes, you gave me the right idea. For some reason, it didn't work, but I used "use="complete.obs"" and it works now. I really appreciate your help! One more thing, I am trying to include a new variable which is a ratio of two other variables like this: ``` v <- finaliniai %>% select(berd_mio_eur, RRDIN_by_TOT_TURN_PC, INNO.y, uibepart, uibedvaintrca, ENTRP_EDU_PC, RRDEX_BY_TOT_TURN_PC, avg_prsnnl_costs_ths_eur, berd_mio_eur/TOT08_TU) ``` but it doesn't work. – Kristijonas Medelis Jul 30 '19 at 19:59
  • You cannot create new variables in `dplyr::select` call. Use `dplyr::mutate` instead. – Gabriel M. Silva Jul 30 '19 at 20:15
  • @GabrielSilva Sorry to bother you again but if I use mutate instead of select then from what I got v is changed to a different class(not numeric) and I can't draw the correlation. – Kristijonas Medelis Jul 30 '19 at 20:23
  • It is really hard to know what is going on just by the name of the variables. You should always provide an example data (look up for [reprex](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)) to give people an idea of your problem. As far as I can help, dividing a numeric column by another numeric column (be either integer or double) always give you a numeric column. You can quick check your columns types with `str()`. – Gabriel M. Silva Jul 30 '19 at 20:41

0 Answers0