[R] Please Help. Subtraction of Matrices?

Jonathan Baron baron at cattell.psych.upenn.edu
Thu Oct 31 11:52:38 CET 2002

On 10/30/02 22:58, g barlow wrote:
>I am just beginning to learn R.  Please help. I have two matrices. One 20 
>columns by 16 rows represent student responses on a 20 question test. The 
>second is 20 by 16 representing the correct responses 16 
>times.  Subtracting one from the other should yield 0's if a response is 
>correct.  Yet Response minus Bigkey doesn't work.

It should work.  Look at what you get when you do it.  An error
message?  Some matrix other than what you expect?

Possibly Response or Bigkey is not actually a matrix.  Try

Also try making up some data and running the same commands (with
smaller matrices perhaps).

Once you get it working, you can simplify it a bit by trasposing
Response with t() and just typing the key once, as a vector.  R
will recycle the vector column by column, e.g.

t(Response) - LittleKey

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