Hi, I'm trying to calculate correlation coefficients and p values for a dataset using rcorr. I got an error which I think means it doesn't like that some of the variables are stored as double:
Warning in storage.mode(x) <- "double" : NAs introduced by coercion
Error in rcorr(as.matrix(fisherData)) :
NA/NaN/Inf in foreign function call (arg 1)
I then went back to convert the relevant variables to numeric and repeatedly failed. I tried using =numeric and got the invalid length argument error:
Show in New Window
Error: Problem with mutate() column MSL_PC1_16. MSL_PC1_16 = numeric(MSL_PC1_16).
x invalid 'length' argument
I then tried using as.numeric, and the code ran fine, but when I checked the data type was still double. I then tried several variations of that as suggested by other posts here, all of which "ran" without actually changing the data type.
There is not a separate data type named double in R. That is the same as numeric. I suggest you look at the result of as.matrix(fisherData). Is it a matrix of numbers or characters?
It's definitely a matrix, there's a mix of numbers and characters. The code was running fine before I added a few new variables.
If having the data type as double is fine, do you know what I would need to do to fix the error with the correlation matrix that sent me down this road in the first place? (See top of original post).
Unfortunately the data isn't mine, its my boss's and she's generally very protective of data before its published so I probably shouldn't. For now I think I'll just exclude the variables that are causing issues and do something else with them, because its just preliminary diagnostics. Thanks so much for your help though! Really appreciate it
If you have a mixture of "numbers and characters" in the matrix then all the elements in the matrix will be character (see example below) and this explains @ FJCC example. You cannot convert the alphanumerics to numerals and so R is coercing them to NA
Is there a specific reason that the data is being stored in matrices? Usually, assuming the numeric data and character data are in separate columns one would use data.frames to store the data.