[R] Beginner troubles.
Roger D. Peng
rpeng at jhsph.edu
Thu Aug 26 20:46:48 CEST 2004
Your function is not vectorized. See the FAQ
(http://cran.r-project.org/doc/FAQ/R-FAQ.html), question 7.19.
-roger
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:
>
>
>>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?
>
More information about the R-help
mailing list