You could do something like this:
# data
nrows - 2L
ncols - 5L
myVec - array(rnorm(nrows * ncols), dim = c(nrows, ncols))
y - rnorm(ncols)
temp - t(myVec) - y
result - colSums(temp * temp)
# check
all.equal(as.numeric(crossprod(myVec[1L, ] - y)), result[1L])
#...
(And don't use a
Hi Wei Wu,
What about:
x - matrix(rnorm(2*5),ncol=5)
y - rnorm(5)
distances - rowSums((x-y)**2)
Cheers,
Tsjerk
On Wed, Aug 24, 2011 at 8:43 AM, Enrico Schumann
enricoschum...@yahoo.de wrote:
You could do something like this:
# data
nrows - 2L
ncols - 5L
myVec -
Yes, sorry, so the distance is
colSums((t(x)-y)**2)
(I knew that) :S
Tsjerk
On Wed, Aug 24, 2011 at 9:19 AM, Enrico Schumann
enricoschum...@yahoo.de wrote:
R will subtract the vector columnwise from the matrix (so the vectors need
be the columns).
x - matrix(0, nrow = 10L, ncol = 5L)
y -
On Wed, 24 Aug 2011, Tsjerk Wassenaar wrote:
Yes, sorry, so the distance is
colSums((t(x)-y)**2)
(I knew that) :S
Did you know that ** is deprecated (and almost undocumented), so your
readers can hardly be expected to understand that? Please use the
documented operator ^ .
Tsjerk
On
4 matches
Mail list logo