I have a dataset named bwght
which contains the variable cigs
(cigarattes smoked per day)
When I calculate the mean of cigs
in the dataset bwght
using:
mean(bwght$cigs)
, I get a number 2.08.
Only 212 of the 1388 women in the sample smoke (and 1176 does not smoke):
summary(bwght$cigs>0)
gives the result:
Mode FALSE TRUE NA's
logical 1176 212 0
I'm asked to find the average of cigs
among the women who smoke (the 212).
I'm having a hard time finding the right syntax for excluding the non smokers = 0 I have tried:
mean(bwght$cigs| bwght$cigs>0)
mean(bwght$cigs>0 | bwght$cigs=TRUE)
if (bwght$cigs > 0){ sum(bwght$cigs) }
x <-as.numeric(bwght$cigs, rm="0"); mean(x)
But nothing seems to work! Can anyone please help me??
See Question&Answers more detail:os