0

Hey I have a data set in which the col1 is the index for point1, col2 is the index for point2, the last col is the distance. I want to do some quick analysis using R packages. so I try to use the method mentioned: Converting pairwise distances into a distance matrix in R

 point1   point2  distance  
 6839    14606   0.129411764706
 9693    7211    0.24347826087
 7854    303 0.0360920970753
 13628   13628   0.47619047619
 6868    3754    0.0182291666667
 460 293 0.122362869198
 3188    13063   0.041095890411
 22968   1992    0.412844036697
 477 105 0.0642201834862
 332 2808    0.00982800982801
 5690    4749    0.75
 7420    584 0.92125984252
 20082   1280    0.160256410256
 20477   144 0.0277777777778
 25280   20  0.00256081946223

after I do the

as.dist(xtabs(df[, 3] ~ df[, 2] + df[, 1]))

it reports:

In as.dist.default(xtabs(df2[, 3] ~ df2[, 2] + df2[, 1])) : non-square matrix

what's the issue? how to fix it? Thanks!

Community
  • 1
  • 1
user1830108
  • 195
  • 1
  • 15
  • `xtabs(distance ~ point1 + point2, df)`. You should probably look at http://stackoverflow.com/questions/9617348/reshape-three-column-data-frame-to-matrix and/or look at the igraph package. – Frank Jul 08 '16 at 15:30
  • Hey Frank, Thanks! but i want have a sparse matrix of the column and row to be sorted all points (all detected point1 + point2) – user1830108 Jul 08 '16 at 15:38
  • What I meant was that I do not see the error you mention, possibly because when I read in your data, I'm seeing something different from what you see. Consider making your problem more reproducible, complete with desired output, as described here http://stackoverflow.com/a/28481250/ – Frank Jul 08 '16 at 15:41
  • is there a way i could upload my dataset instead of benchmark data sets mentioned/simple self generated dataset? because it is not couples of lines can generated in my case, unluckily – user1830108 Jul 08 '16 at 15:51
  • It's generally discouraged. Since you seem to be running into a syntax problem, I doubt a large example is needed to illustrate it. By the way, you might be interested in the r chat room if a lot of discussion is needed for your issue: http://chat.stackoverflow.com/rooms/25312/r-public It's pretty empty over the weekend, though. – Frank Jul 08 '16 at 15:57

0 Answers0