[R] Ranking

Ashta sewashm at gmail.com
Sat Nov 14 23:28:28 CET 2015


Hi all,

I have the following raw data some records  don't have the second variable.

test <- read.table(textConnection(" Country  STATUS
USA
USA    W
USA    W
GER
GER    W
GER    w
GER    W
UNK    W
UNK
UNK    W
FRA
FRA
FRA    W
FRA    W
FRA    W
SPA
SPA    W
SPA          "),header = TRUE,  sep= "\t")
test

It is not reading it correctly.

Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
  line 17 did not have 2 elements



After reading   I want change the status column  to numeric so that I
can use the table function

test$STATUS <- ifelse(is.na(test$STATUS), 0,  1)

at the end I want the following table (Country, Won, Lost , Number of
games played and % of score ) and pick the top 3 countries.

COUNTRY   Won   Lost   NG    %W
 USA             2        1         3      (2/3)*100
 GER             3        1         4      (3/4)*100
 UNK             2        1         3      (2/3)*100
 FRA             3         2        5      (3/5)*100
 SPA             1         2         3      (1/3)*100

Thank you in  advance



More information about the R-help mailing list