Re: [R] the quick way to report the invalid value

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Fri 24 Jun 2005 - 14:33:20 EST

On 6/23/05, ronggui <0034058@fudan.edu.cn> wrote:
> for example,in my data d,the value 1:9,NA is valid and the others are invalid.
> and i want to report something like:
> the variable z has invalid value.
>
> is there any function to do so?
>
> i though this will work but fails:
>
> > d
> x y z
> 1 1 NA 1
> 2 2 2 2
> 3 3 3 3
> 4 4 4 4
> 5 5 5 5
> 6 6 6 6
> 7 7 7 7
> 8 8 8 8
> 9 9 9 9
> 10 NA 10 9
>
> >myfun<-function(x) {
> if(any(a<-match(x,NA,nomatch=0)>0))
> cat(deparse(substitute(x)),"has invalid value","\n")}
> >apply(d,2,FUN=myfun)
> newX[, i] has invalid value
> newX[, i] has invalid value

Try looping over the names of d:

junk <- lapply(names(d), function(n) cat(n, d[,n], "\n"))



R-help@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 Received on Fri Jun 24 14:42:04 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:02 EST