Handling a "Mixed Type" Matrix (String, Float64 and Int64)

I am trying to copy a string vector into a numerical matrix (2D) column and having some difficulty. I realise Julia one needs to take note on how to define the matrix type. Please see my simple test example below. The code as written works, as I am only dealing with integers. However, when I try to add the string vector (Vector_Month_Names) to myMatrix I get errors. Can anyone see what I am doing wrong or am I trying to do the impossible?

Thanks,

Peter

using CSV
using DataFrames
using DelimitedFiles

myMatrix =zeros(12,2)
#myMatrix = Array{Any,2}
Vector_Month_Names = Array{String,1}
Vector_Month_Names = ["Jan","Feb","Mar","Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]

function foo()
    j=12

    for i in 1:j
        a= i 
        b=2*i
        c = Vector_Month_Names[i]
        myMatrix[i,:] = vcat(a,b)
        #myMatrix[i,:] = vcat(a,b,c)
    end

    df=DataFrame(myMatrix)
    CSV.write(joinpath(pwd(),"Test_Ouput.csv"),  df, delim=',',decimal='.', newline="\r\n")    # Writes to current directory
    println(myMatrix[12,2], Vector_Month_Names[3])

end

foo()

You could consider doing this:

julia> T = Union{String,Int}
Union{Int64, String}

julia> myMatrix = Matrix{T}(undef,12,3)
12×3 Matrix{Union{Int64, String}}:
 #undef  #undef  #undef
 #undef  #undef  #undef
 #undef  #undef  #undef
 #undef  #undef  #undef
 #undef  #undef  #undef
 #undef  #undef  #undef
 #undef  #undef  #undef
 #undef  #undef  #undef
 #undef  #undef  #undef
 #undef  #undef  #undef
 #undef  #undef  #undef
 #undef  #undef  #undef

julia> for i in 1:j
           a= i 
           b=2*i
           c = Vector_Month_Names[i]
           myMatrix[i,:] = vcat(a,b,c)
       end

julia> myMatrix
12×3 Matrix{Union{Int64, String}}:
  1   2  "Jan"
  2   4  "Feb"
  3   6  "Mar"
  4   8  "Apr"
  5  10  "May"
  6  12  "Jun"
  7  14  "Jul"
  8  16  "Aug"
  9  18  "Sep"
 10  20  "Oct"
 11  22  "Nov"
 12  24  "Dec"

Otherwise, I think DataFrames.jl is what you might want instead of a matrix.

Perfect. Many thanks Peter