[R] Odp: Relative frequency on a character vector

Ista Zahn izahn at psych.rochester.edu
Thu Jan 20 15:29:04 CET 2011


Hi,

On Tue, Jan 18, 2011 at 3:48 PM, ADias <diasandre at gmail.com> wrote:
>
> 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"?

See ?chartr for character case conversion.

>
> 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?

Seems pretty direct to me... what exactly are you looking for?

>
> 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.
>
> ______________________________________________
> 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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list