TELL ME

you are viewing a single comment's thread
view the rest of the comments
[–] 14 points 2 years ago* (last edited 2 years ago) (3 children)

Ever wondered what’s the difference between NA and NULL?

Let’s say you have a string of numbers like 5, 8, NA, 3.

What’s the first number? It’s 5.

What’s the third one? It’s NA (missing).

What’s the seventeenth number? It’s NULL, meaning it doesn’t even make any sense to request a number like that when this vectors is so short.

BTW some programs/languages may treat these terms differently.

  • source
  • hideshow 6 child comments
  • [–] 4 points 2 years ago (1 child)

    I do a lot of training for our new hire data analysts. My favorite lesson is explaining to them how this applies in the tools we use. You can get a feel for how someone's brain works by their reaction. Horror, wonder, or pop...always fun.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 3 points 2 years ago (2 children)

    But what about empty string, and what’s the difference between NULL and “NULL”? Is NaN a null number?

  • source
  • parent
  • hideshow 4 child comments
  • [–] 2 points 2 years ago

    So there is the "it depends" answer, but generally:

    NULL means a value doesn't exist in memory, usually because the variable was never given a value, or because the variable was given the null value.

    "NULL" is a string with the word null written in all caps. It's not an empty string and it's not NULL. It's a value with the word "NULL".

    "" is an empty string. It's not NULL because technically it's fully initialized value. It's a string that has a length of 0 characters.

    NaN is not a number. A value could or could not exist, but if it's not a number then if you check for a number you could get NaN.

  • source
  • parent
  • [–] 1 point 2 years ago (1 child)

    It depends on the context. What was described as NA in that example by be NULL or NaN in another application. For example, excel power query would call it NULL, which I find baffling having used R.

    It’s basically Wild West out there. There are no rules, there is only chaos.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 2 years ago (1 child)

    Interesting. I've never wondered about that though.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 1 point 2 years ago

    You don’t have to until you start wondering why a particular value in your program is NULL instead of a number. Then you realize that the program is trying to do something completely absurd like find the tenth number of a vector that has only 5 values.

  • source
  • parent