Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Male > Female equal to TRUE in R, Excel, and VBA? How about in other languages?

Tags:

r

excel

vba

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...).

enter image description here

So I wonder, what really happened here? Could anyone here explain it to me? Does this hold TRUE, too, for other programming languages? Why?

like image 409
Anastasiya-Romanova 秀 Avatar asked Mar 06 '18 07:03

Anastasiya-Romanova 秀


People also ask

What is the difference between true and false in Excel?

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.

Are men and women really equal?

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.

What are the different types of comparison operators in VBA?

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. ...

How to test if two cell values are not equal to each other?

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.


1 Answers

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.

like image 64
Florian Avatar answered Nov 02 '22 23:11

Florian