R Lookup data “falsly” returns NA

Hi R community,

I have 2 data tables in R (DT_Paths and DT_Nodes):

DT_Paths is a table with a source and a destination, and a count which returns the amount of exchanges between source and destination:

sapply(DT_Paths, mode) Source Destination Count "character" "character" "numeric"

DT_Nodes is a table with all unique sources and destinations (column name 'studieprogramma'), and a numerical lookup value (in column 'lookup'):

sapply(DT_Nodes, mode) Studieprogramma lookup Index "character" "numeric" "numeric"

In table DT_Paths I would like to add the numerical equivalent of each source and destination by using the lookup function:

DT_Paths$SourceNum <- lookup(DT_Paths$Source, DT_Nodes)

The new column SourceNum, however, only returns NA, indicating there is no match between the 2 tables. Visually (and also in Excel), the values in the 2 tables give a match but apparently the current R code is unable to see this match. At least that's what I think the problem is.

Does anyone have an idea how I could change the lookup function or the data type of the tables to get the match? Do I need to use another function? ...

Thanks in advance

Hi, it is very difficult to give you concrete steps to solve your problem without reproducible example. Please have a look at this guide, to see how to create one:

In general, what you doing is very likely doable and not very difficult.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.