如果任何一列为空,如何替换同一行中“GID”列中的字符“N”
DataFile <- extract_tables("new.pdf",pages = c(87),
method = "stream", output = "data.frame", guess = TRUE)
DataFrame<-as.data.frame(DataFile)
#removing No. and A# from columns
df2<-subset(DataFrame, Group!="No." & Group!="A#")
输出:
GID ColA ColB
1 2 2
2 3 4
3 5 4
4 6 5
5 6 5
NG1 8
MG2 8 1
MG3 8 1
NG4 8
预期输出:
GID ColA ColB
1 2 2
2 3 4
3 5 4
4 6 5
5 6 5
G1 8 N
MG2 8 1
MG3 8 1
G4 8 N
数据:
df1 <- structure(list(GID = c("1", "2", "3", "4", "5", "NG1", "MG2",
"MG3", "NG4"), ColA = c(2L, 3L, 5L, 6L, 6L, 8L, 8L, 8L, 8L),
ColB = c("2", "4", "4", "5", "5", "", "1", "1", "")), row.names = c(NA,
-9L), class = "data.frame")