Probably a simple answer, but I'm having trouble.
Why is the following the case?
colnames(handx[[x]][2])
[1] "Player vs. L"
> colnames(handx[[x]][2]) == "Player vs. L"
[1] FALSE
Thanks
Probably a simple answer, but I'm having trouble.
Why is the following the case?
colnames(handx[[x]][2])
[1] "Player vs. L"
> colnames(handx[[x]][2]) == "Player vs. L"
[1] FALSE
Thanks
The issue you're encountering is likely due to hidden characters or whitespace in the column name. To diagnose the issue, you can print the column name with surrounding quotes to see if there are any hidden characters:
cat("'", colnames(handx[[x]][2]), "'", sep = "")
If you see any extra characters or whitespace, you can remove them using trimws()
or gsub()
functions:
clean_colname <- trimws(colnames(handx[[x]][2]))
clean_colname <- gsub("\\s+", " ", clean_colname) # Replace multiple spaces with a single space
Then, you can compare the cleaned column name with the target string:
clean_colname == "Player vs. L"
If this still returns FALSE
, there might be some other hidden characters that need to be removed. You can use the gsub()
function to remove specific characters if needed.