I have a DataFrame containing counts of a binary variable (yes/no). I would like to code the counts as instances of 1 = yes and no = 0.
Here is a simple example of the Dataframe with the same structure as my dataset:
initial DataFrame
Row │ subject response count
│ Int64 String Int64
─────┼──────────────────────────
1 │ 1 yes 2
2 │ 1 no 0
3 │ 2 yes 2
4 │ 2 no 1
The example below shows the desired result after coding counts of yes to 1 and counts of no to 0
desired DataFrame
Row │ subject y
│ Int64 Int64
─────┼────────────────
1 │ 1 1
2 │ 1 1
3 │ 2 1
4 │ 2 1
5 │ 2 0
How can this be accomplished with DataFrames.jl or another package?
Thank you.
MWE
using DataFrames
df1 = DataFrame(
subject = [1,1,2,2],
response = ["yes","no","yes","no"],
count = [2,0,2,1]
)
df2 = DataFrame(
subject = [1,1,2,2,2],
y = [1,1,1,1,0],
)