简体   繁体   中英

How to Merge Column of Clusters and Columns with X-Y coord?

I have a column with the name of the points, a column with the X coordinates and a column with Y coordinates.

This is the tab on which I'm working:

在此处输入图片说明

I want to create a tab in which I have three columns, one with Clusters ' ID, one with X coordinates and another with Y coordinates. And for each ckustr I want the XY coordinates.

I've tried the following code:

Xcoord <- sort(unique(tabprof$X_coord))

clusters <- sort(unique(tabprof$Cluster_ID))

I've tried do this in order to merge the two vectors, but it wasn't possible, because they have a different number of rows. It's probably due to the presence of clusters with the same X coord value.

Due to our talk in comments, I'll provide new solution. I'll use fake data.

A <- c(1,1,1,1,2,2,2,2)
B <- c(3,3,4,4,3,3,3,5)
df <- data.frame(A,B)
res <- unique(df)


> df
  A B
1 1 3
2 1 3
3 1 4
4 1 4
5 2 3
6 2 3
7 2 3
8 2 5

> res
  A B
1 1 3
3 1 4
5 2 3
8 2 5

So as you se if our A column is ClusterID and B X-coords, we have ClusterID duplicated but! we have unique coord to each one. What is more if two different IDs have the same coords it's no problem. I hope that it'll helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM