【发布时间】:2023-01-12 06:06:35
【问题描述】:
说我有
a <- c(0:3, NA)
我希望用 1 替换 0,用 0 替换 1。也就是说,我想要 a <- c(1, 0, 2, 3, NA)。由于NA,以下代码不起作用
> a[a<2] <- 1- a[a<2]
Error in a[a < 2] <- 1 - a[a < 2] :
NAs are not allowed in subscripted assignments
我知道如果我们使用函数,我们可以使用na.rm = T。如何在我的案例中添加这样的论点?
【问题讨论】:
标签: r