This post similar with this post Replace NA in column with value in adjacent column But now if x6=0, it must be return by value of x5. If i do so
mydat$X6[0(mydat$X6)] <- mydat$X5[0(mydat$X6)]
of course i have this Error: attempt to apply non-function
mydat=structure(list(ItemRelation = c(158200L, 158204L), DocumentNum = c(1715L,
1715L), CalendarYear = c(2018L, 2018L), X1 = c(0L, 0L), X2 = c(0L,
0L), X3 = c(0L, 0L), X4 = c(NA, NA), X5 = c(107L, 105L), X6 = c(0,
0)), .Names = c("ItemRelation", "DocumentNum", "CalendarYear",
"X1", "X2", "X3", "X4", "X5", "X6"), class = "data.frame", row.names = c(NA,
-2L))
How to replace zero by x6 on x5 value to get derided output
ItemRelation DocumentNum CalendarYear X1 X2 X3 X4 X5 X6
1 158200 1715 2018 0 0 0 NA 107 107
2 158204 1715 2018 0 0 0 NA 105 105