Make column names more robust

develop
parent 91fc553c4c
commit 4b66ad8b1f
Signed by: millironx
GPG Key ID: 139C07724802BC5D

@ -58,6 +58,9 @@ function beefblup(path::String, savepath::String, h2::Float64)
# Import data from a suitable spreadsheet
data = DataFrame(CSV.File(path))
# Make sure the data is in the proper format
renamecolstospec!(data)
# Sort the array by date
sort!(data, :birthdate)
@ -293,5 +296,23 @@ function additiverelationshipmatrix(id::AbstractVector, damid::AbstractVector, s
return A
end
"""
renamecolstospec(::DataFrame)
Renames the first four columns of the beefblup data sheet so that they can be referred to by
name instead of by column index, regardless of user input.
"""
function renamecolstospec!(df::DataFrame)
# Pull out the fixed-effect and observation name
othernames = propertynames(df)[5:end]
# Put specification column names and user-defined names together
allnames = cat([:id, :birthdate, :dam, :sire], othernames, dims=1)
# Rename in the DataFrame
rename!(df, allnames, makeunique=true)
return df
end
end

Loading…
Cancel
Save