[R] wilcox.test; data type conversion?

Par Leijonhufvud
Fri, 29 Oct 2010 03:37:03 -0000

I'm working on a quick tutorial for my students, and was planning on
using Mann-Whitney U as one of the tests.

I have the following (fake) data

 grade <- c("MVG", "VG", "VG", "G",
"MVG", "G", "VG", "G", "VG")
 sex <- c( "male", "male", "female",
"male", "female", "male", "female",
"male", "male")
 gradesbysex <- data.frame(grade, sex)

The grades is in the Swedish system, where the order is G < VG < MVG

The idea is that they will investigate if they can show a grade
difference by sex (i.e. that the teacher gives better grades to boys or
girls).

Since the wilcox.test needs the order of the grades it wants numeric
vector  for the data. Is there a good and simple (i.e. student
compatible) way to handle this? I could tell them to enter data as
numbers instead, but an elegant way to do this inside R would be
preferable.


On the same theme, is there a way to tell barplot that, when making
stacked barplots, to stack the data in a particular order (default
appears to be alphabetical)?