[R] newbie question on dist

Saurav Pathak saurav at sas.upenn.edu
Thu Dec 19 16:23:02 CET 2002


hi,

i have just begun using R, so please bear with me.

i am trying to use cmdscale and display the result.  i read the data
using read.table(), calculate the proximity matrix using dist() and
the display the result using the cmdscale().  this is very fine.

in addition, i want the display to distinguish between two classes
of records in my data.  i have my data records marked as "1" or "0".
so i want to display 1's and 0's.  how may i do that?

i use the following code:

----
> fj <- read.table("fj")
>  names(fj)
[1] "V1" "V2" "V3" "V4" "V5" # "V5" contains the class mark (1 or 0)
> #
> # since i dont want the class attribute in the distance matrix
> # i create another data.frame dropping it.  but how do i pass it
> # so that I may use it while plotting?
> fjN <- data.frame(V1=fj$V1, V2=fj$V2, V3=fj$V3, V4=fj$V4)
> library(mva)
> fjNDist <- dist(fjN, method="euclidean")
> fjCMDS <- cmdscale(fjNDist)
> plot(x, y, type="n", main="cmdscale(fjNDist)")
> text(x, y, ".", cex=0.8)
----

any help will be much appreciated.

thanks,
saurav




More information about the R-help mailing list