【发布时间】:2019-04-25 22:15:42
【问题描述】:
我是使用 R 的新手。我正在使用一个数据集,并且缺失值已替换为“?”在我得到数据之前。我正在寻找一种方法来删除包含它的行。它不仅仅针对某一行,而是在所有行中。
我已经尝试过Delete rows containing specific strings in R,但它对我不起作用。到目前为止,我已经在下面包含了我的代码。
library(randomForest)
heart <- read.csv(url('http://archive.ics.uci.edu/ml/machine-learning-databases/echocardiogram/echocardiogram.data'))
names <- names(heart)
nrow(heart)
ncol(heart)
names(heart)
colnames(heart)[colnames(heart)=="X11"] <- "survival"
colnames(heart)[colnames(heart)=="X0"] <- "alive"
colnames(heart)[colnames(heart)=="X71"] <- "attackAge"
colnames(heart)[colnames(heart)=="X0.1"] <- "pericardialEffusion"
colnames(heart)[colnames(heart)=="X0.260"] <- "fractionalShortening"
colnames(heart)[colnames(heart)=="X9"] <- "epss"
colnames(heart)[colnames(heart)=="X4.600"] <- "lvdd"
colnames(heart)[colnames(heart)=="X14"] <- "wallMotionScore"
colnames(heart)[colnames(heart)=="X1"] <- "wallMotionIndex"
colnames(heart)[colnames(heart)=="X1.1"] <- "mult"
colnames(heart)[colnames(heart)=="name"] <- "patientName"
colnames(heart)[colnames(heart)=="X1.2"] <- "group"
colnames(heart)[colnames(heart)=="X0.2"] <- "aliveAfterYear"
names(heart)
【问题讨论】:
-
heart[rowSums(heart == "?") == 0, ] -
看看
?grepl -
这些值是随机丢失还是故意丢失?也许 OP 应该考虑他或她是否应该保留或省略这些字符串。 na.omit 如下面的答案中所建议的那样,而一个好的选项并不总是适合 ML。
标签: r