R: Why I cannot delete rows with NA elements in a data frame? -
i trying delete rows na elements in data frame doing following:
cleaned_data <- data[complete.cases(data),]
however, still getting same data frame without row being removed. running 3.2.1 r version os x 10.10.3. here data:
> dput(data) structure(list(`1` = structure(c(1l, 1l, 6l, 3l, 3l), .label = c("1", "2", "3", "4", "5", "na"), class = "factor"), `2` = structure(c(5l, 5l, 7l, 2l, 2l), .label = c("1", "2", "3", "4", "5", "6", "na" ), class = "factor"), `3` = structure(c(34l, 46l, 66l, 51l, 28l ), .label = c("0", "1", "10", "100", "105", "11", "110", "112", "12", "120", "14", "15", "16", "168", "18", "2", "20", "200", "21", "22", "24", "25", "26", "27", "28", "29", "3", "30", "31", "32", "35", "36", "4", "40", "41", "42", "42099", "42131", "42134", "42197", "42292", "45", "48", "49", "5", "50", "54", "55", "56", "6", "60", "64", "65", "7", "70", "72", "75", "77", "8", "80", "82", "84", "85", "9", "90", "na"), class = "factor"), `4` = structure(c(1l, 2l, 1l, 2l, 1l), .label = c("0", "1", "na"), class = "factor"), `5` = structure(c(1l, 1l, 1l, 1l, 1l), .label = c("0", "1", "na"), class = "factor"), `6` = structure(c(1l, 2l, 1l, 1l, 1l), .label = c("0", "1", "na"), class = "factor"), `7` = structure(c(2l, 2l, 1l, 1l, 1l), .label = c("0", "1", "na"), class = "factor"), `8` = structure(c(1l, 1l, 1l, 1l, 1l), .label = c("0", "1", "na"), class = "factor"), `9` = structure(c(1l, 1l, 1l, 1l, 2l), .label = c("0", "1", "na"), class = "factor")), .names = c("1", "2", "3", "4", "5", "6", "7", "8", "9"), row.names = c(na, 5l ), class = "data.frame")
those aren't true na
s, strings or factors happen "na"
. can turn them real nas:
data[data=="na"] <- na
Comments
Post a Comment