[R] Data Checking

Uwe Ligges ligges at amadeus.statistik.uni-dortmund.de
Sun Mar 24 12:26:39 CET 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!

Assume your "data set" is a data.frame():

 X <- data.frame(a=1:5, b=2:6, ce=c(3,5,7,6,11)) 
 # Let's call it a, b, ce --- c already is a function
 # Now get the rows with errors:
 X[X$a + X$b != X$ce, ]


So you neither need the construct
  if(condition){
	statement
  }
  else{
	statement2
  }

nor
  elseif(condition, statement1, statement2)

Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list