[R] grup function

arun smartpink111 at yahoo.com
Wed Apr 10 23:59:01 CEST 2013


Hi,
The pattern is not clear.  
In this particular case,
library(stringr)
word1<-c("Shangh i", "Hello here i am","h llo")
 word1[str_count(word1," ")==1]<-gsub(" ","a",word1[str_count(word1," ")==1])
 word1
#[1] "Shanghai"        "Hello here i am" "hallo" 


But, this will  not work here:
word2<-c("Shangh i", "B lanced food","h llo")



A.K.



----- Original Message -----
From: Dominic Roye <dominic.roye at gmail.com>
To: R help <r-help at r-project.org>
Cc: 
Sent: Wednesday, April 10, 2013 6:58 AM
Subject: [R] grup function

Hello,

How can i mattch blanks within words, when i have more phrases?

c("Shangh i", "Hello here i am","h llo")


> gsub(" ","a",c("Shangh i", "Hello here i am","h llo"))
[1] "Shanghai"        "Helloahereaiaam" "hallo"


I would like to have [1] "Shanghai"  "Hello here i am" "hallo"

I hope someone can help me.


Thanks,

    [[alternative HTML version deleted]]

______________________________________________
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