[R] What is "print print print" ?

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Thu Dec 6 16:11:20 CET 2012


You should be careful that you really want to convert the underlying numeric representation of a factor to your Rank variable ( see str(Vote) ). If you only have three levels as shown it will work, but if you have more than one digit you will probably need to use the as.is argument to the read.table function and use string operations to get rid of the brackets before converting to numeric. Factor variable can be a blessing, but seem more of a curse if you don't understand them.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

Vladimir eremeev <wl2776 at gmail.com> wrote:

>Yes, now I see.
>It's ridiculous that I haven't noticed this elementary error, which I
>know
>of for over 10 years. :)
>
>Now my problem, it's another question.
>
>Here is the code and data, as requested.
>
>Sample data, I've copied a part of text file:
>
> Charge Strobe [1]
> Charge FC     [2]
> Charge SG     [3]
>
> Carcass FC      [1]
> Carcass Strobe [2]
> Carcass SG      [3]
>
> Chart    Strobe  [1]
> Chart    FC      [2]
> Chart    SG      [3]
>
> Boy  Strobe [1]
> Boy   FC      [2]
> Boy   SG      [3]
>
> Wires   Strobe  [1]
> Wires   SG      [2]
> Wires   FC      [3]
>
>Now I read them and make last column numeric:
>
>votes<-read.table("comparison.txt", col.names=c("Object", "Method",
>"Vote"))
>    votes$Rank <- as.numeric(votes$Vote)
>
>Now I want to see for each method how many it has first, second and
>last places:
>
>    for(m in levels(votes$Metod)) {
>print(c(m, hist(votes[with(votes, Method == m), "Rank"], breaks=0:3,
>plot=FALSE)$counts))
>    }
>
>Oups... And now I've found my error, thanks to Opera's spell checker.
>I have missed the letter 'h' in Method.




More information about the R-help mailing list