丢弃 200 个随机健康实例

Discard 200 random healthy instances

丢弃 200 个随机健康实例。 我如何在 Rstudio 中实现它?

这是数据框:

https://www.kaggle.com/code/jamaltariqcheema/model-performance-and-comparison/data

我试过了,但出现错误。

kidney_disease$hd <- ifelse(test=kidney_disease$hd == 0, yes="Healthy", no="Unhealthy")

也许以下解决了问题。
使用 sample 随机选择行号,将默认值 "Healthy" 分配给新列 hd,并将值 "Unhealthy" 分配给随机选择的行。

set.seed(2022)   # Make results reproducible

i <- sample(nrow(kidney_disease), 200)
kidney_disease$hd <- "Healthy"
kidney_disease$hd[i] <- "Unhealthy"