Reputation: 31
In R, I have been having trouble trying to create a correlation matrix for my data. I keep running into this problem: "Error in cor(mydata) : 'x' must be numeric" and I don't know how to fix it.
> mydata <- Combo[, c(1,2,3,4,5,6,7)]
> head(mydata, 13)
> #computing matrix
> corrmax = cor(mydata)
**Error in cor(mydata) : 'x' must be numeric**
>
Upvotes: 2
Views: 6548
Reputation: 66
I believe not all the data in mydata
are numeric. You can test this by running: str(mydata)
or sapply(mydata, is.numeric)
.
If there are variables in mydata
that are chr
or other non-numeric formats or return FALSE
in the case of sapply
, you will need to convert them to numeric before running the command or be more selective about the set of variables for which you calculate a correlation. I see strings and percent signs in what you posted. The strings will need to be removed and the formatted percents (%) converted to a numeric representation (decimals).
Upvotes: 3