Hi Veda:
following your example:
example=as.data.frame(cbind(x=c(0,0,1,1,0),x2=c('no','yes','yes','yes','no'),
x3=c('no','yes','yes','no','no'),x4=c(1,0,1,1,0)),
stringsAsFactors = FALSE)
Note that i have added stringsAsFactors = FALSE... I also added one row to your example, so you can have a column with only 0 and 'no' and see the difference in the output
Now you can get a vector indicating a logical value TRUE if the row only have 0 or 'no'
onlidesired <- apply(example, 1, function(x) mean(x == 0 | x == 'no')==1)
> onlidesired
[1] FALSE FALSE FALSE FALSE TRUE
So the last row is the one that matches your criteria.
To calculate the proportion of 0 and 'no' of each row, we follow the same way, but now, we assign it to a new variable of example:
example$proportions <- apply(example, 1, function(x) mean(x == 0 | x == 'no'))
> example
x x2 x3 x4 proportions
1 0 no no 1 0.75
2 0 yes yes 0 0.50
3 1 yes yes 1 0.00
4 1 yes no 1 0.25
5 0 no no 0 1.00
Hope it helps:
cheers