Home > front end >  How to create NA matrix in Julia?
How to create NA matrix in Julia?

Time:08-15

I am successful to create this NA matrix using this R code.

tree=matrix(NA,nrow=(4),ncol=(4))
tree

Output:- enter image description here

How to do the same in Julia?

CodePudding user response:

We may use

Array{Union{Missing, String}}(missing, 4, 4)

CodePudding user response:

Try using DataFrames. It gives you row and column names and a myriad of tabular data features.

julia> using DataFrames

julia> DataFrame(Matrix{Any}(missing, 4,4), :auto)
4×4 DataFrame
 Row │ x1       x2       x3       x4      
     │ Any      Any      Any      Any     
─────┼────────────────────────────────────
   1 │ missing  missing  missing  missing 
   2 │ missing  missing  missing  missing 
   3 │ missing  missing  missing  missing 
   4 │ missing  missing  missing  missing

CodePudding user response:

The missings function from Missings.jl is designed for this use-case:

julia> using Missings

julia> missings(Int, 3, 4)
3×4 Matrix{Union{Missing, Int64}}:
 missing  missing  missing  missing
 missing  missing  missing  missing
 missing  missing  missing  missing

(note that it is recommended to pass a type of elements that you want to later store in this martix)

  • Related