Re: [R] Print occurrence / positions of words

2013-04-26 Thread S Ellison
> >I have tried some different packages in order to build a R program > which will take as input a text file, produce a list of the > words inside that file. Each word should have a vector with > all the places that this word exist in the file. How about txt <- paste(rep("this is a nice text

Re: [R] Print occurrence / positions of words

2013-04-22 Thread arun
Hi, May be this helps: vec<- "this is a nice text with nice characters" library(stringr)  vec2<-unlist(str_match_all(vec,"\\w+")) #or # vec2<-str_split(vec," ")[[1]] res<-unique(lapply(vec2,function(x) which(!is.na(match(vec2,x)  names(res)<- unique(vec2) res #$this #[1] 1 # #$is #[1] 2 # #$