【发布时间】:2019-02-08 05:54:19
【问题描述】:
此帖与此帖相似 Replace NA in column with value in adjacent column 但现在如果 x6=0,则必须按 x5 的值返回。 如果我这样做了
mydat$X6[0(mydat$X6)] <- mydat$X5[0(mydat$X6)]
当然我有这个错误: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))
如何在 x5 值上用 x6 替换零以获得可嘲笑的输出
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
【问题讨论】:
标签: r dplyr data.table plyr