# How to make a function recognize datatype argument

**URL:** <https://discourse.julialang.org/t/how-to-make-a-function-recognize-datatype-argument/42499>\
**Category:** New to Julia\
**Created:** [July 3, 2020, 11:27pm UTC](https://discourse.julialang.org/t/how-to-make-a-function-recognize-datatype-argument/42499 "2020-07-03T23:27:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkarikom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkarikom/32/7096_2.png) [@mkarikom](https://discourse.julialang.org/u/mkarikom)\
**Post date:** [July 3, 2020, 11:27pm UTC](https://discourse.julialang.org/t/how-to-make-a-function-recognize-datatype-argument/42499/1 "2020-07-03T23:27:45Z")

</div>

Here is a function that is supposed to turn a vector of strings to an Array{Union{Missing,Int64}:

```julia
function NAtoMissing(data::Array{Any,1},nonmissing::DataType,tomissing::Any)
    withmissing = Array{Union{Missing, nonmissing},1}(missing,length(data))
    for i = 1:length(data)
        if data[i] == tomissing
            withmissing[i] = missing
        else
            withmissing[i] = parse(nonmissing,data[i])
        end
    end
    withmissing
end

test = ["1", "2", "NA"]
NAtoMissing(test,Int64,"NA")

```

Output:

```julia
MethodError: no method matching NAtoMissing(::Array{String,1}, ::Type{Int64}, ::String)
Closest candidates are:
  NAtoMissing(!Matched::Array{Any,1}, ::DataType, ::Any) 
....

```

So it’s complaining that my second argument is not ::DataType, yet:

```julia
typeof(Int64) 
DataType

```

Obviously I’m not reading this correctly…

edit: fixed the update line in function

---

<div class="post-metadata">

**Author:** ![mkarikom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkarikom/32/7096_2.png) [@mkarikom](https://discourse.julialang.org/u/mkarikom)\
**Post date:** [July 3, 2020, 11:40pm UTC](https://discourse.julialang.org/t/how-to-make-a-function-recognize-datatype-argument/42499/2 "2020-07-03T23:40:49Z")

</div>

Misread the error message, the problem was not with the second argument but with the first.  
This fixes it: data::Array{Any,1} → data::Array{\<: Any,1}

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [July 3, 2020, 11:47pm UTC](https://discourse.julialang.org/t/how-to-make-a-function-recognize-datatype-argument/42499/3 "2020-07-03T23:47:02Z")

</div>

Note that you could write the `Array{<:Any, 1}` as `Vector`.
