xiaodai
xiaodai

Reputation: 16064

Julia: How to use/access the null value?

In R the NA value is available by default however in Julia when I tried

function a()::Array{Union{Int64,Null})
  return [1, null, 2]
end
a()

it gives the error

UndefVarError: Null not defined

How do I use null in Julia?

Upvotes: 2

Views: 1684

Answers (3)

xiaodai
xiaodai

Reputation: 16064

Missing's missing

x = [1, missing, 2]
typeof(x)

Upvotes: 0

Jim K
Jim K

Reputation: 26

For any future readers of this question, this has been resolved in v1 via the missing object.

function a()::Array{Union{Int64, Missing}}
  return [1, missing, 2]
end

You can use the skipmissing function with array operators if you wish to ignore any missing values.

Upvotes: 1

Michael K. Borregaard
Michael K. Borregaard

Reputation: 8044

The representation of nullable values is one of the biggest current discussions in julia, and one of the biggest hurdles for the 1.0 version step. The easiest at the moment is probably to use the NA defined in DataFrames (which uses DataArrays)

function a()::DataArray{Int64}
   return @data [1, NA, 2]
end

Read also https://juliadata.github.io/DataFrames.jl/stable/man/getting_started/#The-NA-Value-1

Upvotes: 4

Related Questions