I have a string '982323.1' and would like to replace everything after the '.' with a '41'. So the string should look like '982323.41'. The code I use to do this is sub('\.$','41',982323.1) This works fine as long as there is only 1 digit after the decimal. If I have '982323.10', then the result of the code is '982323.141' instead of '982323.41' How do I fix the code to replace all characters after the decimal by 41? Thank you -D
Dhiren DSouza wrote:> I have a string '982323.1' and would like to replace everything after the > '.' with a '41'. So the string should look like '982323.41'. The code I > use to do this is > > sub('\.$','41',982323.1)You have to escape "\", see ?regexp: sub('\\.[[:digit:]]*$','\\.41', "982323.1") Uwe Ligges> This works fine as long as there is only 1 digit after the decimal. If I > have '982323.10', then the result of the code is '982323.141' instead of > '982323.41' > > How do I fix the code to replace all characters after the decimal by 41? > > Thank you > > -D > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! R-project.org/posting-guide.html