[R] Placeholders for String Operations
arun
smartpink111 at yahoo.com
Wed Sep 4 17:35:35 CEST 2013
Hi,
gsub("#%", "[percentagevalue]", text1)
#[1] "this is a number 23%"
gsub("\\d+%$", "[percentagevalue]", text1)
#[1] "this is a number [percentagevalue]"
gsub("bla", "23", text2)
#[1] "this is not a number 23%"
A.K.
----- Original Message -----
From: Simon Pickert <simon.pickert at t-online.de>
To: r-help at r-project.org
Cc:
Sent: Wednesday, September 4, 2013 11:17 AM
Subject: [R] Placeholders for String Operations
Hi all,
what are the placeholders for string operations/modifications? Is there a placeholder for numbers, which would allow me to easily replace all numbers in a string? Something like
text1 <- c("this is a number 23%")
text2 <- c("this is not a number bla%")
newtext1 <- gsub(#%, [percentagevalue], text)
newtext2 <- gsub(#%, [percentagevalue], text)
newtext1 should be "this is a number [percentagevalue]"
newtext2 should be "this is not a number 23%"
I figured there is * ? . but I can't find a source that explains their use and lists other placeholders..
Appreciate your help!
Thanks
Simon
______________________________________________
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