[R] picking out eigenvalues of 1
Tamas Papp
tpapp at axelero.hu
Fri Apr 2 16:22:08 CEST 2004
After making
E <- eigen( something )
I would like to extract those eigenvectors which have an eigenvalue of
1. If I had an isone() function, I would simply say
E$vectors[,which(isone(E))]
but the problem is that I have no such thing. I found all.equal, so I
could test for all.equal(x, 1), but for complex numbers, I need to use
something like all.equal(x, 1+0i), don't I?
I tried writing one,
isone <- function (x) {
sapply(E$values - rep(1+0i, 16), function (x) {
if(identical(all.equal(x, 0+0i), TRUE)) TRUE else FALSE })
}
and it works, but looks like a complicated hack. Would it be possible
to improve that? The subtraction of 1+0i is there to make sure that
the result is complex.
Thanks,
Tamas
PS.: I have been asking a lot of "it already works, but would it be
possible to do it better" questions. I just want to learn the "way of
R", and this list seems to be the perfect place for that. Sorry if I
am wasting anybody's time.
--
Tamás K. Papp
E-mail: tpapp at axelero.hu
Please try to send only (latin-2) plain text, not HTML or other garbage.
More information about the R-help
mailing list