I have the following code where firstly I add the values for each index from two columns and creating Vector{Int64}
df = CSV.read(joinpath("data", "data.csv"), DataFrame)
adding_columns = df.firstcolumn df.secondcolumn
Then I will create a function as following:
function fnct(data::Vector{T}; var= 8) where { T <: Number }
V = []
for x in 1:size(data)[1]
strt = x-var
ending = x var
avg = 0
if strt < 1
for y in 1:x var
avg = avg data[y]
end
avg = avg/(x var-1)
elseif ending > size(data)[1]
for y in x-var:size(data)[1]
avg = avg data[y]
end
avg = avg/(size(data)-x-var)
else
for y in x-var:x var
avg = avg data[y]
end
avg = avg/(2*var)
end
push!(V,avg)
end
return V
end
When trying:
typeof(adding_columns)
I will get:
Vector{Int64}
however when calling
fnct(adding_columns)
I will get:
ERROR: MethodError: no method matching -(::Tuple{Int64}, ::Int64)
I presume that it takes my adding_columns as Tuple but I do not get it why, when the typeof is giving me Vector.
How could I solve this problem?
CodePudding user response:
size(data)
is a tuple:
julia> size([1,2,3]::Vector{Int})
(3,)
...but you're subtracting an integer from it in avg = avg/(size(data)-x-var)
.
Did you mean avg = avg/(length(data)-x-var)
or avg = avg/(size(data, 1)-x-var)
?