Re: [R] how to store a vector of vectors

2010-11-13 Thread Alexx Hardt
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

Re: [R] how to store a vector of vectors

2010-11-13 Thread 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 > x <- c(1,1,1) > matrix(x, nrow=2, ncol=3) [,1] [,2] [,3] [1,]111 [2,]1

Re: [R] how to store a vector of vectors

2010-11-13 Thread Alexx Hardt
Am 13.11.2010 14:39, schrieb Sarah Goslee: I at least would need to see an actual example of your code to be able to answer your question. My function: norm <- function(x,y){ sqrt( rowSums( (x-y)^2 ) ) } y <- matrix( c( 1,1,1, 2,3,4), nrow=2, byrow=TRUE) x <- c(1,1,1) H

Re: [R] how to store a vector of vectors

2010-11-13 Thread Duncan Murdoch
Alexx Hardt wrote: Hi, I'm trying to write a function to determine the euclidean distance between x (one point) and y (a set of n points). How should I pass y to the function? Until now, I used a matrix like that: | [,1] [,2] [,3] [1,] 0 2 1 [2,] 1 1 1 |

Re: [R] how to store a vector of vectors

2010-11-13 Thread Sarah Goslee
I at least would need to see an actual example of your code to be able to answer your question. But why not just use dist() and take the appropriate column of the resultant matrix? mydist <- function(x, amat) { # x is the single variable as a vector # amat is the remaining variables as rows alldi

[R] how to store a vector of vectors

2010-11-13 Thread Alexx Hardt
Hi, I'm trying to write a function to determine the euclidean distance between x (one point) and y (a set of n points). How should I pass y to the function? Until now, I used a matrix like that: | [,1] [,2] [,3] [1,] 0 2 1 [2,] 1 1 1 | Which would pass the p