Hi:

Make grade an ordered factor:
grade <- factor(grade, levels = c('G', 'VG', 'MVG'))
as.numeric(as.character(grade)) will convert to numeric scores 1, 2 and 3,
respectively, corresponding to the numerical codes of the ordered levels.

HTH,
Dennis

On Thu, Oct 28, 2010 at 8:37 PM, Par Leijonhufvud
<p...@hunter-gatherer.org>wrote:

> 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)?
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to