[R] symbolic matrix elements...

Duncan Murdoch murdoch at stats.uwo.ca
Mon Sep 18 19:52:47 CEST 2006


On 9/18/2006 1:16 PM, Evan Cooch wrote:
> 
> Eik Vettorazzi wrote:
>> test=matrix(c( expression(x^3-5*x+4), expression(log(x^2-4*x))))
>> works.
> Well, not really (or I'm misunderstanding). Your code enters fine (no 
> errors), but I can't access individual elements - e.g., test[1,1] gives 
> me an error:
> 
>  > test=matrix(c( expression(x^3-5*x+4), expression(log(x^2-4*x))))
>  > test[1,1]
> Error: matrix subscripting not handled for this type
> 
> Meaning...what?

Matrices in R are just vectors with a dim attribute.  The matrix 
function let you create the matrix, but the [ function doesn't know what 
to do when the vector is of mode expression.

This is an unimplemented case, a limitation (or perhaps bug if it wasn't 
intentional) in R.

>> btw. you recieved an error because D expects an expression and you 
>> offered a list
> 
> OK - so why then are each of the elements identified as an expression 
> which I print out the vector? Each element is reported to be an 
> expression. OK, if so, then I remain puzzled as to how this is a 'list'.

The problem is that if m is a list, then m[1] is a list with one 
element.  You wanted m[[1]] to extract the first element and get 
something that's not a list.

Duncan Murdoch



More information about the R-help mailing list