[R] how to store a vector of vectors

Alexx Hardt mikrowelle1234 at gmx.de
Sat Nov 13 16:07:14 CET 2010


Am 13.11.2010 15:48, schrieb Sarah Goslee:
> You are assuming that R is using row-major order
> for recycling elements, when in fact it is using column-
> major order.
>
> It doesn't show up in the first case, because all the
> elements of x are identical
>    

Oops. Mental note made.

> norm<- function(x, y) {
>    
> + x<- matrix(x, nrow=nrow(y), ncol=ncol(y), byrow=TRUE)
> + sqrt( rowSums( (x-y)^2 ) )
> + }

Ha, thank you!
I am now using this line:
sqrt( rowSums( t( (x-t(y)) )^2 ))
It seems to work, do you see anything wrong with it?

I will have to read up and play around with those "object" thingys you 
mentioned -- I am still new to R (and OOP, if that matters).

Thanks again,
  Alex



More information about the R-help mailing list