[R] For help in R coding

Daniel Malter daniel at umd.edu
Mon Jul 4 00:56:23 CEST 2011


Say you have the string x in a matrix

x<-c('a,..gGGtTaac<!T','caaGGTT,,.!!@CC')
x<-matrix(x)

remove all punctuation:

x1<-gsub('[[:punct:]]','',x)
x1

convert all letter to lowercase

x2<-gsub('(\\w*)','\\L\\1',x1,perl=T)
x2

now for each row split the string and table it. apply over all rows in the
matrix

apply(x2,1,function(x) table(strsplit(x,'')))

HTH,
Daniel



--
View this message in context: http://r.789695.n4.nabble.com/For-help-in-R-coding-tp3639413p3642655.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list