Pretty new to R and to stackexchange. My apologies if I make any faux pas.
I'm working with the North Carolina births data from irss.unc.edu. I have a data frame NCBIRTH1450 with several lists, all of which have numeric or NA values. I'm just trying to calculate some proportions from the data. For one of the lists, I'm able to get the proportion of male babies by using
pBoyBaby <- sum(SEX==1)/sum(!is.na(SEX))
The above returns a numeric value for pBoyBaby. My aim is to take the number of matching values and divide by the number of non-missing values, and I get an appropriate result.
However, when I attempt the same function on another column of the same type,
pMomSmokes <- sum(SMOKE==1)/sum(!is.na(SMOKE))
The object pMomSmokes takes the value NA. How could I identify the difference between the natures of SMOKE and SEX, for instance, that explain this discrepancy? I really don't know why it's doing this.
In case it's relevant, SEX has values of either 1 or 2 -- with no NA's -- while SMOKE has the values 0 or 1, with a few NA's.
Thanks!
Rapplications (even though at present that good stuff is found primarily in comments :-). – whuber♦ Apr 10 '12 at 19:38