I have a problem about how to count missing variables in dataset. I have a question for my customer. They are must choice one of answer for example: A, B, C, D and E. Now, I have dataset which is the result from my question, for instance: x1 x2 x3 x4 x5 A A A B A C A A A A B B A B A B B B C A A B B B B C B B B A I know that my customer only choice A, B and C. Are there any way to count variables that are not include in dataset. I mean D and E is missing in dataset. Thanks for your help. Jan Sabee
Something like:
sum(sapply(dat, function(x) ! x %in% c("A", "B",
"C")))
probably would work.
HTH,
Andy
> From: Jan Sabee
>
> I have a problem about how to count missing variables in dataset.
> I have a question for my customer. They are must choice one of answer
> for example: A, B, C, D and E.
> Now, I have dataset which is the result from my question, for
> instance:
>
> x1 x2 x3 x4 x5
> A A A B A
> C A A A A
> B B A B A
> B B B C A
> A B B B B
> C B B B A
>
> I know that my customer only choice A, B and C.
> Are there any way to count variables that are not include in dataset.
> I mean D and E is missing in dataset.
>
> Thanks for your help.
> Jan Sabee
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
>
On Mon, 21 Mar 2005 12:07:16 +0100 Jan Sabee wrote:> I have a problem about how to count missing variables in dataset. > I have a question for my customer. They are must choice one of answer > for example: A, B, C, D and E. > Now, I have dataset which is the result from my question, for > instance: > > x1 x2 x3 x4 x5 > A A A B A > C A A A A > B B A B A > B B B C A > A B B B B > C B B B A > > I know that my customer only choice A, B and C. > Are there any way to count variables that are not include in dataset. > I mean D and E is missing in dataset.You just need to set up the variables properly. If you just say: R> x <- factor(sample(LETTERS[1:3], 5, replace = TRUE)) R> summary(x) A B C 1 2 2 R will assume that the only levels available are A-C. But if you tell R R> x <- factor(x, levels = LETTERS[1:5]) R> summary(x) A B C D E 1 2 2 0 0 it will do what you want. Just provide the full choice set as levels to the corresponding variables. Z> Thanks for your help. > Jan Sabee > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >