我有两个数据集:
#> dput((h_NDVI))
structure(list(Date = structure(c(15235, 15236, 15237, 15238,
15239, 15240, 15241, 15242, 15243, 15244, 15245, 15246, 15247,
15248, 15249, 15250, 15251, 15252, 15253, 15254, 15255, 15256,
15257, 15258, 15259, 15260, 15261, 15262, 15263, 15264, 15265,
15266, 15267, 15268, 15269, 15270, 15271, 15272, 15273, 15274,
15275, 15276, 15277, 15278, 15279, 15280, 15281, 15282, 15283,
15284, 15285, 15286, 15287, 15288, 15289, 15290, 15291, 15292,
15293, 15294, 15295, 15296, 15297, 15298, 15299, 15300, 15301,
15302, 15303, 15304, 15305), class = "Date"), NDVI = c(NA, NA,
0.294432928636906, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, 0.278673565052068, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, 0.352506101806382, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.377174364841906,
NA, NA, NA)), row.names = 160:230, class = "data.frame")
和
#> dput(head(r和om_h_NDVI,23))
structure(list(N = c(22L, 25L, 27L, 56L, 69L, 81L, 83L, 96L,
100L, 106L, 124L, 138L, 139L, 150L, 153L, 162L, 171L, 174L, 181L,
187L, 205L, 206L, 227L), Date = structure(c(15097, 15100, 15102,
15131, 15144, 15156, 15158, 15171, 15175, 15181, 15199, 15213,
15214, 15225, 15228, 15237, 15246, 15249, 15256, 15262, 15280,
15281, 15302), class = "Date"), NDVI = c(NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.2944329, NA, NA, NA,
NA, NA, NA, 0.3771744)), row.names = c(98L, 91L, 23L, 79L, 163L,
34L, 191L, 59L, 7L, 213L, 52L, 134L, 209L, 176L, 58L, 165L, 16L,
92L, 171L, 28L, 164L, 137L, 3L), class = "data.frame")
A quick explanation of the exercise: I've chosen r和om points from h_NDVI 和 created the r和om_h_NDVI.
Now I want to replace all values of the NDVI column from h_NDVI with NA that have a coincident Date with r和om_h_NDVI (this includes the NA's which will remain NA).