Q:

How to replace a character column and insert a new column with binomial presence vs. absence data instead

Okay, I have done this before using the if() function, but I can't seem to be able to do it here.
My data looks like this:
sex
NA
NA
NA
hembra
hembra
NA
NA
hembra
NA
NA
NA
NA
NA
NA
NA
macho
NA
NA
NA

and I would like to insert a new column to make a presence vs. absence column  so it look like this:
sex     Animal.present
NA      0
NA      0
NA      0
hembra  1
hembra  1
NA      0
NA      0
hembra  1
NA      0
NA      0
NA      0
NA      0
NA      0
NA      0
NA      0
macho   1
NA      0
NA      0
NA      0

I eventually wish to aggregate into other groups so that I may calculate the sum of certain things eg. total macho / hembra etc 

A:

Try
df$Animal.present <- ifelse(is.na(df$sex),0,1)

