我有这三个专栏.在"Basiswert"中有一些NA值.如果"Basiwert"中有NA值,我想用Basiwert形式的相同数字替换它,该数字出现在"D"或"E"列中. 例如:在第2行中,Basiswert的值中有一个NA.此值必须替换为E列第3行的USDCAD = 12442.
structure(list(D = c("12449", "12448", "12447", "12446", "12442",
"12441", "12440", "12439", "12438", "12437"), E = c("0", "12442",
"12442", "12430", "0", "12430", "12436", "12436", "12430", "12430"
), Basiswert = c("EURJPY", NA, "USDCAD", "EURAUD", "USDCAD",
"EURAUD", NA, "GBPJPY", NA, "EURAUD")), class = "data.frame", row.names = c(NA,
-10L))
编辑:
library(dplyr)
data %>% mutate(Basiswert = ifelse(is.na(Basiswert) == FALSE &
D == E, Basiswert, NA))
不起作用了.