To replace numbers in one dataset with characters from another dataframe, you can use the match() function in R. Here's an example:
main.r351 chars17 lines
This will output:
main.r68 chars5 lines
In this example, match() is used to find the position of each number in df1 within the num column of df2, and then the corresponding character from df2 is used to replace the number.
Note: This assumes that the numbers in df1 are exact matches for the numbers in df2$num. If there are any missing values or mismatches, the result will be NA.
Alternatively, you can use dplyr package to achieve this:
main.r114 chars9 lines
This will produce the same output as the previous example. The across() function applies the replacement to all columns in df1.
gistlibby LogSnag