-1
我有一個帶有<NA>
的字符列,我想用行下面的字符替換它。下面是一個例子:用以下行中的字符替換缺少的字符值使用R
df12 <-
structure(
list(Reg = structure(c(NA, 1L, 1L, NA, 1L, 1L, NA, 2L, 2L, NA, 2L, 2L, NA, 2L, 2L)
, .Label = c("A", "B"), class = "factor")),
.Names = "Reg", row.names = c(NA, -15L), class = "data.frame")
df12
Reg
1 <NA>
2 A
3 A
4 <NA>
5 A
6 A
7 <NA>
8 B
9 B
10 <NA>
11 B
12 B
13 <NA>
14 B
15 B
library(dplyr)
所需的輸出
1 A
2 A
3 A
4 A
5 A
6 A
7 B
8 B
9 B
10 B
11 B
12 B
13 B
14 B
15 B