Hi,
I want to relpace the id number in"dataframe id" with it corresponding value in dta1. However, why the result in dta2 about id=981,990 is NA? i want to still use the way based on example code. Thank you for help in advance.
id<-data.frame(c(1,2,3,4,990,981))
dta1<-data.frame(id=c(1,2,3,4,5,6,980,981,990,991,992),
value=c(10.1,9.6,6.3,3.6,5.5,1.9,7.7,8.3,9.9,1.2,15.1))
colnames(id)<-"id"
lookup<-dta1$value
names(lookup)<-dta1$id
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
dta2<-id|>mutate(across(.cols = everything(),.fns = ~lookup[.x]))
Created on 2022-11-18 with reprex v2.0.2