I wanted to use left join function for these two datasets. Let me call the upper one as "a", and enter image description here the lower one is "b". enter image description here But it didn't work, and I found that it's because common variable(column) used to join them are incompatible types. Thus, I wanted to join these by "link_id" but that of a is integer and that of b is character. Both are data frame as you can see in the pictures, and I thought this would be easy to solve, by running "as.integer(b)". But the error 'list' object cannot be coerced to type 'integer' was returned despite I saw the data type is dataframe by using str function... And I also tried "as.integer(b$link_id)", but 'warning message : NAs introduced by coersion' was returned. But there wasn't any NA value in dataframe. When I ignore this warning message and run left_join(a, b), it still returns it can't because of incompatible types of key variable... So what should I do now? I think currently the best option is finding the way list to dataframe.
Asked
Active
Viewed 48 times
-3
-
Please share minimal sample data and expected output. See [how to ask a good R question](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). In short: Less verbose text. More code & data. Also make sure you share what you've tried; it helps us understand what you're trying to do. – Maurits Evers Jul 29 '22 at 06:24
-
Please provide enough code so others can better understand or reproduce the problem. – Community Jul 29 '22 at 16:39
1 Answers
0
Convert b$link_id
to numeric and then use merge
:
b$link_id=as.numeric(b$link_id)
merge(a,b,by="link_id")

Basti
- 1,703
- 3
- 10
- 25
-
Really appreciate your fast answer. I applied this, and still warning messages : In as.numeric(b$link_id) : NAs introduced by coersion was returned. But the difference was, it worked and the file was created. Would it be OK if I ignore this warning? – fkdl dmxmx Jul 29 '22 at 06:34
-
I don't have the overall dataset so I cannot see why there is the warning message. Probably you have non-numeric values in your link_id columns, which have been replaced by NA, you should check your link_id names. Otherwise I suggest you to convert `a$link_id` to character and keep `b$link_id` as character and do the merge again – Basti Jul 29 '22 at 06:48
-