[R] two questions about character manipulation

Rui Barradas ruipbarradas at sapo.pt
Sun Sep 16 17:53:01 CEST 2012


Hello,

Try the following.

1)
pattern <- "response."
m <- regexpr(pattern, ex) #gregexpr to get all "response"
regmatches(ex, m)

2)
gsub("\\$", "\\.", ex)

Hope this helps,

Rui Barradas
Em 16-09-2012 15:35, Özgür Asar escreveu:
> Dear all,
>
> I want to manipulate a character string such as
>
> ex<-"cbind(data$response1,data$response2)"
>
> in R in two ways:
>
> 1) extracting the "response1" portion of ex
> 2) replacing "$" with "."
>
> I am wondering that is it possible efficiently doing these in R?
>
> Best
>
> Ozgur
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/two-questions-about-character-manipulation-tp4643292.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