[R] Beginner troubles.
Roger Bivand
Roger.Bivand at nhh.no
Thu Aug 26 21:01:48 CEST 2004
On Thu, 26 Aug 2004, Gaute B Strokkenes wrote:
> I'm new to R. Having read through a good chunk of "An Introduction to
> R" I'm trying to use R to do some relatively straight-forward
> (mathematically speaking) stuff.
>
> I have a file which contains the coordinates of a set of points in
> R^3, with one point per line (i.e. three real numbers). The aim is to
> read that file in and produce the set of all the distances between all
> possible different pairs of points in that file. So I try:
outer() is maybe more difficult than need be, unless this isn't the real
question. Perhaps look at dist() first - it solves your declared problem
directly in a single command, but that makes me think your question was
actually about outer, not distances?
Roger
>
> > a <- read.table("FL_BR14.xyz")
>
> > dim(a)
> [1] 329 3
>
> > A <- function(i) a[i, ]
>
> > A(1)
> V1 V2 V3
> 1 -1558.364 16.97055 1004.381
>
> > d <- function(x, y) sqrt(sum((x - y) * (x - y)))
>
> > outer(1:length(a[, 1]), 1:length(a[, 1]), function(u,
> v) d(A(u), A(v)))
> Error in outer(1:length(a[, 1]), 1:length(a[, 1]), function(u, v) d(A(u), :
> dim<- : dims [product 108241] do not match the length of object [1]
>
> This last error has me stumped. Could anyone give me a pointer in the
> right direction?
>
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no
More information about the R-help
mailing list