all.equal comparison not aligned

Hi all, I was trying to compare the equality of two strings and both contained either leading or trailing whitespace.

May I know why such equality isn't valid? And how should I resolve this?


a <- "   total 2 pints"
b <- " total 2 pints  "
ta <- trimws(a)
tb <- trimws(b)

ta == tb

this shows at least the expected behaviour.
so if you cant match the trimmed text (ta,tb) then I would break down each to their characters and get the ascii numbers corresponding, then you can evaluate a difference in any of the numbering.


tac <-unlist(strsplit(ta,""))
tab <-unlist(strsplit(tb,""))
asc <- function(x) { strtoi(charToRaw(x),16L) }
sapply(tac,asc)
sapply(tab,asc)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.