[R] Odp: Relative frequency on a character vector

ADias diasandre at gmail.com
Tue Jan 18 21:48:59 CET 2011


I have done like this to get the result I need more directly

A<-c("Tell me how many different letter this vector has?")
prop.table(table(strsplit(A,"")))

        ?    a    c    d    e    f    h    i    l    m    n    o    r    s   
t 
0.16 0.02 0.04 0.02 0.02 0.14 0.04 0.06 0.04 0.06 0.04 0.04 0.04 0.06 0.04
0.10 
   T    v    w    y 
0.02 0.02 0.02 0.02 

two questios:

1) is there a direct way of making capital "T" the same as lower case "t"?

2) And can I avoid on the strslipt function to exclude the "?" and the
spaces between words?

I know I can do:

x<-table(strsplit(A, "")) 
]
> x

a c d e f h i l m n o r s t T v w y 
2 1 1 7 2 3 2 3 2 2 2 3 2 5 1 1 1 1 

My question is always to find out if there's a more direct way of doing
this?

Regards,
A.Dias


-- 
View this message in context: http://r.789695.n4.nabble.com/Relative-frequency-on-a-character-vector-tp3221319p3223966.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list