Comparison of identical string evaluated as FALSE

Hi,
I have been trying to compare two columns of a data.frame for their identity, but strangely I'm getting FALSE for the exact string when evaluating from data.frame but evaluated as TRUE when compared separately.
I'm confused about this behaviour...!!!

primers$primer_seq[1]
[1] "ACAGGTACGTTAATAGTTAATAGCGT"
primers$check[1]
[1] "ACAGGTACGTTAATAGTTAATAGCGT"
primers$primer_seq[1] == primers$check[1]
[1] FALSE
'ACAGGTACGTTAATAGTTAATAGCGT' == 'ACAGGTACGTTAATAGTTAATAGCGT'
[1] TRUE

I get around this with

string <- "ACAGGTACGTTAATAGTTAATAGCGT"
frame <- data.frame(c(first = string, second = string))
identical(frame$first,frame$second)
#> [1] TRUE
1 Like

There appears to be an invisible character at the front of the string in your first variable. That accounts for the FALSE and also may explain why copying and pasting it makes comparisons work.

At least that's what I found when I copied from your post.

2 Likes

Yeah there appears to be one invisible character in some of the rows in one column, Thanks a lot...!!!

1 Like

This topic was automatically closed 7 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.