How to analyze categorical data? I have a data set where one of the variables is categorical with two levels, Yes and No. I am trying to run the function cor() to find the correlation between all the variables but since the categorical variable is not numbers I get the prompt that x must be numeric. 
I've read a few places that I don't need to change the variable to a dummy variable because R does it for me but I can't run the function I need. How can I fix this?
 A: The cor function is R's standard function for computing Pearson, point-biserial,  Spearman and Kendall correlations. Even though many of those work well on ordinal data, the function does not work on the data type ordered which is R's data type for ordinal data.
I consider it a quirk of the language, that you have to convert ordinal data to numeric datatypes in order to compute Spearman or Kendall correlations.
Beware that after you converted this, there is no safety measure in place to restrict you from computing "Pearson" correlations from orginally ordinal data.
x1 <- ordered(c("A", "B", "C", "D", "A", "A"))
x2 <- ordered(c("a", "b", "c", "d", "d", "b"))

# this does not work
cor(x1, x2, method = "spearman")

#this works:
cor(as.numeric(x1), as.numeric(x2), method = "spearman")

# BEWARE this will run without throwing an error
cor(as.numeric(x1), as.numeric(x2), method = "pearson")

It may be a more sensible approach to not use as.numeric but to use rank for the conversion. Spearman correlation thus becomes Pearson correlation on ranks, which is statistically correct:
> cor(as.numeric(x1), as.numeric(x2), method = "spearman")
[1] 0.3947368
> cor(rank(x1), rank(x2))
[1] 0.3947368

A: Pearson r which assumes interval data (and is used in many correlation analysis) does not make sense for categorical data. Spearman's rho assumes at least ordinal data and if your data is ordinal that might make more sense.
If you assume a theoretical interval latent variable or you have data that has two levels only than polychoric correlations may make sense. From old memory its often recommended for likert data for example. 
I work in SAS so I don't know if you can do these in R.
