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