# conditional mean statement

#### m.lindebjerg

##### New Member
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) }

#### m.lindebjerg

##### New Member
Thank you so much! It works! And it is so simple