I'm currently taking the course: Introduction to R on DataCamp and in one exercise (Battle of the sexes) there is an instruction like this:
Read the code in the editor and click 'Submit Answer' to test if
male
is greater than (>
)female
The above instruction inspired me to test the following code in RStudio:
'Male' > 'Female'
To my surprise, R gave me the output TRUE
! I also tried in Excel and VBA, and both came up with outputs TRUE
, too! Now, I begin to think that they're programming languages with sexist views (Just kidding, hehe...).
So I wonder, what really happened here? Could anyone here explain it to me? Does this hold TRUE
, too, for other programming languages? Why?
In the mathematical calculation, always TRUE is equal to 1, and False is equal to 0. Sometimes when we apply calculations on TRUE and False, then the result will be like: If we want to get the result as TRUE, we directly use the TRUE formula, and Excel will return the logical value TRUE as output.
Men and women are both equal. Although men and women may be different in some respects, it is important to remember that differences between men and women do not mean that one gender is worse than the other. For example, men and women may be good at different things.
VBA Comparison Operators – Not Equal to & More 1 Equal To. The Equal to operator checks if two values are equal and returns True or False. ... 2 Not Equal To. The Not Equal to operator checks if two values are not equal and returns True or False. ... 3 Greater Than. ... 4 Greater Than or Equal To. ... 5 Less Than. ... 6 Like Operator. ...
This example will test if two cell values are not equal to each other: MsgBox Range ("A1"). Value <> Range ("B1"). value Another way to compare values is with Variables. In this example, we want check if Integer Variable intA is not equal to intB. If this is true, the value of Boolean variable blnResult will be True, otherwise, it will be False.
For R, see help('>')
or its documentation here, and the wikipedia link about collation:
"Comparison of strings in character vectors is lexicographic within the strings using the collating sequence of the locale in use: see locales. The collating sequence of locales such as en_US is normally different from C (which should use ASCII) and can be surprising. Beware of making any assumptions about the collation order: e.g. in Estonian Z comes between S and T, and collation is not necessarily character-by-character – in Danish aa sorts as a single letter, after z."
So summarizing; in your locale, the value of 'F' is smaller than the value of 'M' in the collation sequence, and thus Mxxx
is larger than Fyyy
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With