Hey, sorry if this has been addressed before, but I'm really new to R and having trouble with the gsub function. I need a way to make this function exclude certain values from being substituted: ie my data looks something like (15:.0234,10:.0157) and I'm trying to replace the leading 15 with something else - but of course it replaces the second 15 with something else too. If there's a way to exclude anything with a leading decimal point or something like that, that would do the trick. Thanks yall. -- View this message in context: http://r.789695.n4.nabble.com/Help-with-gsub-function-or-a-similar-function-tp4536584p4536584.html Sent from the R help mailing list archive at Nabble.com.
On Apr 5, 2012, at 10:38 PM, ieatnapalm wrote:> Hey, sorry if this has been addressed before, but I'm really new to > R and > having trouble with the gsub function. I need a way to make this > function > exclude certain values from being substituted: > ie my data looks something like (15:.0234,10:.0157) and I'm trying to > replace the leading 15 with something else - but of course it > replaces the > second 15 with something else too. If there's a way to exclude > anything with > a leading decimal point or something like that, that would do the > trick. > Thanks yall. >Cross-posting to SO and rhelp in quick succession is deprecated. If you hadn't gotten an answer on SO after a day or so, then fine, go a head cross-post but in point of fact you have already gotten three answer on SO so you are just wasting rhelp brain-bandwidth.> -- > View this message in context: http://r.789695.n4.nabble.com/Help-with-gsub-function-or-a-similar-function-tp4536584p4536584.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.David Winsemius, MD West Hartford, CT
You don't provide a reproducible example, or even str(), but I'd guess you need to match "^15" instead of just "15". Sarah On Apr 5, 2012, at 10:38 PM, ieatnapalm <erawls at tulane.edu> wrote:> Hey, sorry if this has been addressed before, but I'm really new to R and > having trouble with the gsub function. I need a way to make this function > exclude certain values from being substituted: > ie my data looks something like (15:.0234,10:.0157) and I'm trying to > replace the leading 15 with something else - but of course it replaces the > second 15 with something else too. If there's a way to exclude anything with > a leading decimal point or something like that, that would do the trick. > Thanks yall. > > -- > View this message in context: http://r.789695.n4.nabble.com/Help-with-gsub-function-or-a-similar-function-tp4536584p4536584.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.