Hi Alex,

What is happening is that the ´dist´function calculates a distance matrix,
and returns an object of the ´dist´ class.

> temp <- rbind (c(10,1),c(99,98))
> x=dist(temp)
> x
         1
2 131.6435
> class(x)
[1] "dist"

You can see a description of the ´dist´class at the end of the function´s
help file.  Do this:
>?dist

So when you do dist(temp) you do not just get a number.  You get an object
that has the distance between the points, plus additional information (i.e.
the method used to calculate the distance, if the matrix contains only the
lower triangle or also the upper triangle and the diagonal, etc.).  If you
do sqrt() or 1/ over this object it is still of the ´dist´ class:

> x=dist(temp)
> x=sqrt(x)
> class(x)
[1] "dist"
> x=1/x
> class(x)
[1] "dist"

Notice that you still the right answer (0.08715662).  For some reason R
prints the attributes of the object when you do the inverse but not when you
do the square root (I´m curious about why...If anyone has an answer please
pitch in).

If you only want to get a number, do this:
> x=as.numeric(dist(temp))
> class(x)
[1] "numeric"
> 1/sqrt(as.numeric(dist(temp)))
[1] 0.08715662

All the best,

Julián

Julian Mariano Burgos
Hafrannsóknastofnunin/Marine Research Institute
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax:  +354-5752001
Netfang/Email: julian@hafro.is, jmburgos@uw.edu


On Thu, Sep 16, 2010 at 10:02 AM, Alaios <alaios@yahoo.com> wrote:

> Hello I have some strange output from R and I try to understand how R
> works.
>
> Could you please help me with that?
>
> temp <- rbind (c(10,1),c(99,98))
> > temp
>     [,1] [,2]
> [1,]   10    1
> [2,]   99   98
>
>
> > dist(temp)
>         1
> 2   131.6435
>
>
> > sqrt(dist(temp))
>         1
> 2   11.47360
>
> so far so good.
>
> until the nex line: when I try to do what i did before but adding the
> 1/(what I
> did before). I was expecting a number as a result of the division but
> unfortunately I took the following:
>
>  1/sqrt(dist(temp))
> [1] 0.08715662
> attr(,"Size")
> [1] 2
> attr(,"Diag")
> [1] FALSE
> attr(,"Upper")
> [1] FALSE
> attr(,"method")
> [1] "euclidean"
> attr(,"call")
> dist(x = temp)
> attr(,"class")
> [1] "dist"
>
>
> Could you please help me understand what is this about?
>
> I would like to thank you in advance for your help
> Best REgards
> Alex
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



--

	[[alternative HTML version deleted]]

