[R] What is "print print print" ?

arun smartpink111 at yahoo.com
Thu Dec 6 14:26:14 CET 2012


Hi,
May be this helps:
Lines<-"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]"
Lines1<-readLines(textConnection(Lines))
 Lines2<-gsub("[][]","",Lines1)
Lines2<-Lines2[Lines2!=""]
votes<-read.table(text=Lines2,header=FALSE,stringsAsFactors=FALSE,col.names=c("Object","Method","Vote"))
 votes$Rank<-as.numeric(votes$Vote)
 ave(votes$Rank,votes$Rank,votes$Method,FUN=length)
 #[1] 4 3 4 1 1 4 4 3 4 4 3 4 4 1 1

#or

 ave(votes$Rank,votes$Rank,votes$Method,FUN=table)
 [1] 4 3 4 1 1 4 4 3 4 4 3 4 4 1 1
#or
 ave(votes$Vote,votes$Vote,votes$Method,FUN=table) 
# [1] 4 3 4 1 1 4 4 3 4 4 3 4 4 1 1
A.K.





----- Original Message -----
From: Vladimir eremeev <wl2776 at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Thursday, December 6, 2012 2:31 AM
Subject: Re: [R] What is "print print print" ?

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.

-- 
Best regards,
Vladimir                            mailto:wl2776 at gmail.com

______________________________________________
R-help at 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.





More information about the R-help mailing list