# [R] Data Checking

Göran Broström gb at stat.umu.se
Sun Mar 24 13:17:07 CET 2002

```On Sun, 24 Mar 2002, Ko-Kang Kevin Wang wrote:

> Hi,
>
> This is a simple question with if elseif....however I am having trouble
> constructing the solution for some reason.
>
> Suppose I have a data set with 3 variables, a, b and c say.  Let's say c
> is the sum of a and b.  So:
>   a  b  c
>   1  2  3
>   2  3  5
>   3  4  7
>   .  .  .
>   .  .  .
>   .  .  .
>
> Suppose that I know there have been some data entry errors and I want to
> check if ALL values in c is really the sum of a and b, and if not, print
> out the whole line (i.e. all values of a, b and c in that row).
>
> Any help on how I can write this if elseif block will be apprecaited!

Try subsetting:

> dataset <- data.frame(a, b, c)
> dataset[a + b != c, ]

is what you want. You should consider whether you want to test exact or
approximate equality, though.

Göran
>
> Ko-Kang
>
> ------------------------------------------------------------------------------
> Ko-Kang Kevin Wang
> Department of Statistics
> University of Auckland
> New Zealand
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

--
Göran Broström                      tel: +46 90 786 5223
professor                           fax: +46 90 786 6614
Department of Statistics            http://www.stat.umu.se/egna/gb/
Umeå University
SE-90187 Umeå, Sweden             e-mail: gb at stat.umu.se

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```