print(k) and you see a lower triangular distance matrix.
k[1] selects distances between 1 and 2
k[2] selects distances between 1 and 3 and so on.
you have a distance matrix, not a single distance value, so you have to
select which distance you need.
Ciao!
mario
On 16-Sep-10 14:38, Alaios wrote:
I fixed by adding this:
k <- sqrt(dist(temp))
k returns sort of a list. So I need to select the first item which is
the result.
a <- k[1]
Can someone explain me why k[1] is needed for that?
Best Regards
Alex
------------------------------------------------------------------------
*From:* Mario Valle <mva...@cscs.ch>
*To:* Alaios <ala...@yahoo.com>
*Sent:* Thu, September 16, 2010 1:28:31 PM
*Subject:* Re: [R] help me understand how things work.
?dist
BTW, to me this does not happens.
x <- matrix(rnorm(100), nrow=5)
d <- dist(x)
1/sqrt(d)
1/sqrt(dist(x))
Hope it helps
mario
On 16-Sep-10 12:02, Alaios 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 <mailto: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.
--
Ing. Mario Valle
Data Analysis and Visualization Group |
http://www.cscs.ch/~mvalle <http://www.cscs.ch/%7Emvalle>
Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91)
610.82.60
v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91)
610.82.82
--
Ing. Mario Valle
Data Analysis and Visualization Group | http://www.cscs.ch/~mvalle
Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60
v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82
______________________________________________
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.