鉴于第一个数据帧中存在一个值,我想用另一个数据帧中的值替换一个数据帧中的值。
第一个数据帧由 1 或 0 的值组成,NA 是占位符。
a <- structure(list(A.1 = c(1L, 0L, NA, 1L, 1L, 0L), A.2 = c(1L, 1L,
1L, NA, 1L, NA), A.3 = c(0L, NA, NA, 0L, NA, NA), A.4 = c(NA,
1L, 1L, NA, 0L, NA), A.5 = c(NA, NA, 1L, NA, NA, NA), A.6 = c(NA,
NA, 1L, NA, NA, 1L)), .Names = c("A.1", "A.2", "A.3", "A.4",
"A.5", "A.6"), class = "data.frame", row.names = c(NA, -6L))
第二个数据帧包含的值应该替换第一个数据帧中 NA 位置的 1 或 0
r <- structure(list(R.1 = c(45L, 33L, 44L, 24L, 32L, 22L), R.2 = c(33L,
99L, 44L, 25L, 25L, 33L), R.3 = c(22L, 77L, 22L, NA, 26L, NA),
R.4 = c(NA, NA, 32L, NA, NA, NA)), .Names = c("R.1", "R.2",
"R.3", "R.4"), class = "data.frame", row.names = c(NA, -6L))
目标是这样的:
d <- structure(list(D.1 = c(45L, 33L, NA, 24L, 32L, 22L), D.2 = c(33L,
99L, 44L, NA, 25L, NA), D.3 = c(22L, NA, NA, 25L, NA, NA), D.4 = c(NA,
77L, 44L, NA, 26L, NA), D.5 = c(NA, NA, 22L, NA, NA, NA), D.6 = c(NA,
NA, 32L, NA, NA, 33L)), .Names = c("D.1", "D.2", "D.3", "D.4",
"D.5", "D.6"), class = "data.frame", row.names = c(NA, -6L))
欢迎任何和所有建议。