Replacing elements within a string in R
Posted
by Maureen
on Stack Overflow
See other posts from Stack Overflow
or by Maureen
Published on 2010-05-24T20:40:09Z
Indexed on
2010/05/24
21:21 UTC
Read the original article
Hit count: 208
r
Hi, I have a row in a data frame in R that is made up of sequences of undetermined length of 0s 1s and 2s as characters. So "01", "010", "201", "102", "00012"... things like this.
I'd like to find a way to determine if the last character in the string is NUMERICALLY the largest. It's important that I keep the row in the data frame as characters for other purposes. So basically I want to take substr(x, nchar(x), nchar(x)) and determine if it, as a number, is the largest of the numbers in the character string.
I'm super lost as to how to do this, since I'm not all that familiar with regular expressions and I have to back and forth between treating elements as characters and numbers.
Thanks in advance.
~Maureen
© Stack Overflow or respective owner