I was wondering if there is a specific parameter to output a table with all the row names when using dist() and as.matrix(). Here's what I mean:
first=c('john', 'judy', 'jenny')
second=c(3,6,9)
third = c(2,4,6)
df = data.frame(first,second,third)
I have this data frame called df:
first second third
1 john 3 2
2 judy 6 4
3 jenny 9 6
Here's my desired output:
john judy jenny
john 0.000000 4.41588 8.831761
judy 4.415880 0.00000 4.415880
jenny 8.831761 4.41588 0.000000
This is my code:
df.dist=dist(df)
df.dist=as.matrix(df.dist, labels=TRUE)
df.dist
And Here's what R is giving me:
1 2 3
1 0.000000 4.41588 8.831761
2 4.415880 0.00000 4.415880
3 8.831761 4.41588 0.000000
I was wondering if there is a specific function or parameter that renames the columns when comparing different entries, or do we just need to code that ourselves?
Another thing that I saw when I typed ?as.matrix is that there is a param called dimnames that lets you input list of names for cols and rows. But I don't know if this would be such a good idea since my dataset has about 100+ entries.
Any help is deeply appreciated. Been stuck for a while.