[R] Checking if a matrix exists/is defined

Richard M. Heiberger rmh at temple.edu
Sun Oct 19 07:50:51 CEST 2014


all() takes a logical argument, not numeric.  See ?all

I think you are looking for
is.null(obj$hessian)

If this isn't what you are looking for, please send a reproducible example
to the entire list.

Rich

On Sun, Oct 19, 2014 at 12:17 AM, Steven Yen <syen04 at gmail.com> wrote:
> Hello
> Can someone help me with the following, specifically in judging
> whether a matrix exists. I have trouble with the first line below. In
> this case, matrix obj$hessian exists and is 74 x 74. I receive the
> error message:
>
> Warning message:
> In all(w$hessian) : coercing argument of type 'double' to logical
>
> Thank you all.
>
> ---
> if (!all(obj$hessian)|OPG){
>    vb<-obj$gradientObs; vb<-solve(t(vb)%*%vb)
>    vb.method<-"; v(b)=inv(G'G)"
> } else {
>    vb<- solve(-obj$hessian)
>    vb.method<-"; v(b)=inv(-H)"
> }
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list