[R] Odp: Relative frequency on a character vector

Petr PIKAL petr.pikal at precheza.cz
Tue Jan 18 14:34:23 CET 2011


Hi

r-help-bounces at r-project.org napsal dne 18.01.2011 13:51:05:

> 
> Hi,
> 
> I have this character vector:
> 
> A<-c("Tell me how many different letter this vector has?")
> 
> Is there a way with R that it can let me know how many different letters 
I
> have on this vector?

A<-c("Tell me how many different letter this vector has?")
x<-strsplit(A, "")
> x
[[1]]
 [1] "T" "e" "l" "l" " " "m" "e" " " "h" "o" "w" " " "m" "a" "n" "y" " " 
"d" "i"
[20] "f" "f" "e" "r" "e" "n" "t" " " "l" "e" "t" "t" "e" "r" " " "t" "h" 
"i" "s"
[39] " " "v" "e" "c" "t" "o" "r" " " "h" "a" "s" "?"

> table(x)
x
  ? a c d e f h i l m n o r s t T v w y 
8 1 2 1 1 7 2 3 2 3 2 2 2 3 2 5 1 1 1 1 
> length(table(x))
[1] 20
> 

Regards
Petr

BTW. There are help pages coming with R installation. Do you have them 
corrupted? There is strsplit in see also section of nchar help page.


> 
> If I use nchar(A) que gives me the number 50. With this function he is
> counting all the letters present and also spaces between the words. Can 
we
> also not count the spaces between words?
> 
> Then after I knew how many different letters there were on the vector I
> wanted to table the number of times each letter is present to calculate 
the
> relative frequency of each.
> 
> Is this possible with R?
> 
> Many thanks
> A.Dias
> -- 
> View this message in context: http://r.789695.n4.nabble.com/Relative-
> frequency-on-a-character-vector-tp3221319p3221319.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.



More information about the R-help mailing list