On Jul 3, 2009, at 1:29 PM, Steven Rytina wrote:
The rules for conformability of objects required for various
operators remain a mystery as do some related problems like the
rules for recycling in creating arrays etc. Would someone be able to
direct me to where such rules are stated?
In a related vein, there are all manner of operations that are
readily coded in Gauss or in MATA that fail, often mysteriously, in
R. Are there some guidelines available?
Not sure. Haven't seen any. Generally the complaint posted here is
that R is not Matlab. Here is one professor's answer to that one:
http://germain.its.maine.edu/~hiebeler/comp/matlabR.pdf
And here is a specific problem:
I would like to carry out logical comparisons between a
(vector?) of length EYE and each row of a JAY by EYE object,
obtaining a conforming JAY by EYE result of comparisons such as
Obj[Jay,Eye] == Vec[Eye]
Any thoughts on how to effect this would be welcome.
> i =10; j=4
> vi <- 1:10
> mji <- matrix(1:40, nrow=j)
> matrix( mapply("==", vi, mji[1:nrow(mji), ] ),
nrow=nrow(mji) , byrow=TRUE)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[2,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[3,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[4,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
The fact that you have reversed the conventional order (for R anyway)
of the indices makes me wonder it that is a source of confusion. You
may have had problems in constructing an appropriate iterative row-
wise comparison if you did not realize that the default order that
matrix elements are filled and accessed is column-wise. The result of
the mapply is just a long vector (and vi gets recycled) so it needs
to be hammered back into conformance to get what you specified.
Among many failed efforts,
as.matrix(7 element Vec) == { an 8 row, 7 column data.frame}
yields a 8 by 7 result
v1 vs Ob[1,1] v2 vs Obj[1,2] ...
v2 vs Ob[2,1] .
. et cetera
.
v7 vs Obj[7,1]
v1 vs Obj[8,1]
while
as.matrix(7 element Vec) == t{ the 8 row, 7 column data.frame}
yields a conformability error.
Thanks for any help or comments.
[[alternative HTML version deleted]]
______________________________________________
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
______________________________________________
R-help@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.