I have following problem that you can easily see after downloading the picture. It would be of great help if you help me solve the problem.
Asked
Active
Viewed 60 times
-3

Md. Mahfuzur Rahman
- 25
- 4
-
4(1) Please don't post images of data and necessary details. (2) Please show your effort so far, SO is not a free-code-service, and it looks like you're asking us to do your homework for you. (3) This seems like a merge/join operation, see https://stackoverflow.com/q/1299871/3358272, https://stackoverflow.com/a/6188334/3358272. – r2evans Jun 23 '21 at 19:31
-
I'm sorry for the inconvenience......but I'm not good in R......the code would have been very helpful for me....Thanks for your suggestion – Md. Mahfuzur Rahman Jun 24 '21 at 04:53
-
you are always welcome. I tried to solve this problem, and I solved this, but it took long time for me when I worked alone to solve the problem. But there is many people in this group, someone of whom could solve my problem in an hour.....if I would have got the code in an hour, I could have done a lot of calculation till now.....so even if someone does my home work, that could be a help to advance a research work.....Although I have solved the problem, still I don't know R, and I'm never gonna b an expert of R.....I believe u understand...... – Md. Mahfuzur Rahman Jul 16 '21 at 11:44
-
1You missed part of my point, but I'll be more specific: you are not spending time asking the question in a way that makes it easy for us to answer. For instance, you're asking us to transcribe an image into usable data so that we can test and demonstrate R code. From this, it appears that you are not putting any effort into this, you are just pasting an image into a question and hoping somebody will do something. Ergo my point about demonstrating no effort. I understand that you do not know R well, that's fine and not my point. – r2evans Jul 16 '21 at 14:12
-
Thanks for the explanation.....I'm sorry for the inconvenience....... – Md. Mahfuzur Rahman Jul 26 '21 at 05:42
2 Answers
0
In Table 1, the IDs are correctly linked up with the values in column A. B contains some values which are not ordered and whose corresponding IDs are not given in corresponding rows. We need to find the IDs of the values in column B by using the IDs of column A. Now if we run following code in R, we will find the IDs corresponding the values in column B
mydata <- read.csv(‘C:/Users/Windows/Desktop/practice_1.csv’)
df <- data.frame(mydata$B, mydata$A, mydata$ID, header=TRUE)
library(qdap)
df[, "New ID"] <- df[, 1] %l% df[, -1]
After running above code, we will find the new ID in the column New ID like Table 2.

user438383
- 5,716
- 8
- 28
- 43

Md. Mahfuzur Rahman
- 25
- 4
-
I applaud the effort, but this is as non-reproducible as the original question. – r2evans Jul 16 '21 at 14:21
0
What you need is a simple match
operation:
table1$ID2 <- table1$ID1[match(table1$z, table1$y)]
table1
# ID1 y z ID2
# 1 0 1 11 10
# 2 1 2 3 2
# 3 2 3 5 4
# 4 3 4 4 3
# 5 4 5 8 7
# 6 5 6 7 6
# 7 6 7 15 15
# 8 7 8 6 5
# 9 8 9 2 1
# 10 9 10 16 17
# 11 10 11 1 0
# 12 11 12 NA NA
# 13 15 15 NA NA
# 14 17 16 NA NA
Please, the next time you ask a question where sample data is necessary (most questions), please provide data in this format:
Data
# dput(table1)
structure(list(ID1 = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15, 17), y = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 16), z = c(11, 3, 5, 4, 8, 7, 15, 6, 2, 16, 1, NA, NA, NA), ID2 = c(10, 2, 4, 3, 7, 6, 15, 5, 1, 17, 0, NA, NA, NA)), row.names = c(NA, -14L), class = "data.frame")

r2evans
- 141,215
- 6
- 77
- 149
-
Thanks for your suggestion, I'll follow the instruction.... – Md. Mahfuzur Rahman Jul 26 '21 at 05:44
-
Also thanks a lot for this code, which is much easier than the others. – Md. Mahfuzur Rahman Jul 26 '21 at 06:07