Sorry this has taken so long to get back to you, I have been out of the office 
a lot recently.
 
The documentation for read.table suggests that since an as.ordered function 
exists, that you could just use "ordered" as a column class, but I don't know 
how well that works in practice.  In general I think it is better to let 
read.table create regular factors, then change them to ordered factors by hand 
afterwards.  For regular factors, the default ordering (since order does not 
matter) is alphabetical by factor level.  This is not usually the correct 
ordering for ordered factors and read.table has no way of knowing what the 
proper order should be.  When you change them by hand you can specify the 
ordering rather than taking the usually wrong default.
 
 

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111



 


________________________________

        From: Birgit Lemcke [mailto:[EMAIL PROTECTED] 
        Sent: Friday, August 24, 2007 2:13 AM
        To: Greg Snow
        Cc: R Hilfe
        Subject: Re: [R] ordered factors in data.frame
        
        
        Thanks a lot Greg for your help. 

        This works fine.

        Normally I use a vector to set the classes for the variables:

        Classe<-cclasses <- c(rep("factor", 14), rep("numeric", 4))
        Table1<-read.table("Name", sep = ";", colClasses = Classe)
        
        
        How can I implement to set colClasses as ordererd factor here.
        
        
        Following works not:
        
        
        Classe<-cclasses <- c(rep("factor", 61), rep("numeric", 14), 
rep("odered", 10))


        Thanks in advance

        Birgit


        
        
        
        

        Am 23.08.2007 um 21:21 schrieb Greg Snow:


                The attach function only attachs a copy of the data (changes to 
the data don't show up in the attached copy).  Also you need to tell R what to 
do with the result of as.ordered (where to save it).

                Try something like:


                        table$V3 <- as.ordered(table$V3)


                Or


                        table <- transform(table, V3=as.ordered(V3) )


                Hope this helps,

                -- 
                Gregory (Greg) L. Snow Ph.D.
                Statistical Data Center
                Intermountain Healthcare
                [EMAIL PROTECTED]
                (801) 408-8111




                        -----Original Message-----
                        From: [EMAIL PROTECTED] 
                        [mailto:[EMAIL PROTECTED] On Behalf Of Birgit Lemcke
                        Sent: Thursday, August 23, 2007 11:28 AM
                        To: R Hilfe
                        Subject: [R] ordered factors in data.frame

                        Hello I need a tiny peace of help. (PPC Mac Os X 
10.4.10; R 2.5.1)

                        I have a data.frame with numeric and factor variables.
                        I would like to convert same of the factors to ordered 
factors.

                        I tried with:

                        attach (table)

                        as.ordered (V3)

                        but this gives me only the V3 Vector as ordred back but 
in 
                        the data.frame (str(Table)) it is still not ordered.

                        How can I do that?

                        Thanks for your help.

                        I am still a beginner.

                        Greetings

                        Birgit

                        Now I would like to
                        Birgit Lemcke
                        Institut für Systematische Botanik
                        Zollikerstrasse 107
                        CH-8008 Zürich
                        Switzerland
                        Ph: +41 (0)44 634 8351
                        [EMAIL PROTECTED]






                        [[alternative HTML version deleted]]





        
        Birgit Lemcke
        Institut für Systematische Botanik
        Zollikerstrasse 107
        CH-8008 Zürich
        Switzerland
        Ph: +41 (0)44 634 8351
        [EMAIL PROTECTED]
         






        [[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch 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