Hi I am wondering how to use transform!()
or transform!()
+ ByRow()
functions to do computations utilizing two or more columns
Essentially I want to perform the the function below however using transform!()
data = Dict(
:age => Array{Int64}([0,1,2,3,4,5,6,7,8,9,10,11]),
:female_pop => Array{Float64}([48283,47195,48140,50017,49189,49543,49951,49758,49728,49909,49051,49233]),
:female_deaths => Array{Int64}([136,8,3,5,2,6,6,2,2,3,2,1])
)
df = DataFrame(data)
# The conditional probability of death
qₓ(Pₓ,Dₓ) = Dₓ ./ (Pₓ .+ 0.5 * Dₓ)
df[:,:cond_prob] = qₓ(df.female_pop, df.female_deaths)
I have tried this using the following code but I get an error
transform!(
df,
[:female_pop, :female_deaths] => ByRow(
x -> x.female_deaths / (x.female_pop + 0.5 * x.female_deaths)
) => :cond_prob2
)
For this I get an MethodError
. ANy ideas how I go about this?