How to replace if a value of the column (GID) starts with char "N" to ColB if the ColB is empty in a Dataframe in R programming
code:
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#")
output:
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
Expected output
GID ColA ColB
1 2 2
2 3 4
3 5 4
4 6 5
5 6 5
NG1 8 N
MG2 8 1
MG3 8 1
NG4 8 N
We can specify a condition such as
Or use
grepl
If we want to replace in any of the columns
-output
data