[R] how to store a vector of vectors
Sarah Goslee
sarah.goslee at gmail.com
Sat Nov 13 14:39:15 CET 2010
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
alldist <- dist(rbind(x, amat))
as.matrix(alldist)[-1,1]
}
Sarah
On Sat, Nov 13, 2010 at 8:22 AM, Alexx Hardt <mikrowelle1234 at gmx.de> 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
> |
>
> Which would pass the points (0,2,1) and (1,1,1) to that function.
>
> However, when I pass x as a normal (column) vector, the two variables
> don't match in the function. I either have to transpose x or y, or save
> a vector of vectors an other way.
>
> My question: What is the standard way to save more than one vector in R?
> (my matrix y)
> Is it just my y transposed or maybe a list or something I don't yet know?
>
> Thanks in advance,
> Alex
>
>
> [[alternative HTML version deleted]]
>
--
Sarah Goslee
http://www.functionaldiversity.org
More information about the R-help
mailing list