【发布时间】:2017-11-11 13:45:29
【问题描述】:
请告知如何将列中的一半值替换为 NA:
# Generate 500 values with a skewed distribution
x1 <- round(rbeta(500,0.5,3)*100,0)
# Assign variable to a data frame
df <- data.frame(x1)
# Replace 250 random values in a column 'x1' to NA
df[sample(x1,250)] <- NA
The following mistake is shown:
Error in `[<-.data.frame`(`*tmp*`, sample(x1, 250), value = NA) :
new columns would leave holes after existing columns
我明白为什么会显示错误,但我想强制更换。请告知我该怎么做。
【问题讨论】:
-
欢迎来到 Stack Overflow,Gregory...看看这个。它将帮助您格式化您的帖子,使其更易于阅读。 stackoverflow.com/editing-help