0

I'm trying to carry out a Wilcox test in R but I am getting the following error:

> wilcox.test(vcrdp ~ vcrnodp, paired=F)
Error in wilcox.test.formula(vcrdp ~ vcrnodp, paired = F) : 
grouping factor must have exactly 2 levels

The data comes from a CSV file with 2 numeric columns and the class in R is also numeric. When I check the levels for each variable I get this:

levels(vcrnodp)
NULL

Do I need to add levels to carry out the test? I've been searching for answers for a while and can't find anything that can help me so far.

Sample of data is:

  Violent_crime_rate_dp Violent_crime_rate_nodp
1                32.262                  23.067
2                 7.838                  15.469
3                75.560                  10.918
4               198.029                  58.888
5                22.802                  61.087
6                25.593                  12.665
Richie
  • 9
  • 3
  • Please provide a reproducible example http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Steven Beaupré May 16 '15 at 18:34
  • 1
    The variable to the right of the `~` needs to be a categorical grouping variable. Can you describe your data more? Usually this issue can be handled by "tidying" the data so that all the values of your current `vcrdp` and `vcrnodp` variables fall into a single column (or variable) and are grouped using a factor variable in a different column (or variable). – dsifford May 16 '15 at 18:38
  • Thanks @DerekSifford. I rearranged the data file so I comparing a categorical variable on the right of the ~ and this has worked. Thank you – Richie May 16 '15 at 18:43

0 Answers0