Я использовал этот код, чтобы найти среднее значение, он каким-то образом работал, когда я запускал блок, но когда я перезапускал весь блокнот, появлялся термин ошибки.
# What is the mean suspension rate for schools overall?
transform(merged_data, suspension_rate_total = as.numeric(suspension_rate_total))
mean(merged_data$suspension_rate_total,na.rm = T)
mean(merged_data[7])
# What is the mean suspension rate for schools with farms > 100?
mean(merged_data$suspension_rate_total[merged_data$farms < 100], na.rm = T)
# What is the mean suspension rate for schools with farms < 100?
mean(merged_data$suspension_rate_total[merged_data$farms < 100], na.rm = T)
argument is not numeric or logical: returning NA[1] NA
Это данные:
Данные
structure(list(schid = c("1030642", "1030766", "1030774", "1030840",
"1130103", "1230150"), farms = c("132", "116", "348", "406",
"68", "130"), foster = c("2", "0", "1", "8", "1", "4"), homeless = c("14",
"0", "8", "4", "1", "4"), migrant = c("0", "0", "0", "0", "0",
"0"), ell = c("18", "12", "114", "45", "7", "4"), suspension_rate_total = c("*",
"20", "0", "0", "95", "5"), suspension_violent = c("*", "9",
"0", "0", "20", "2"), suspension_violent_no_injury = c("*", "6",
"0", "0", "47", "1"), suspension_weapon = c("*", "0", "0", "0",
"8", "0"), suspension_drug = c("*", "0", "0", "0", "9", "1"),
suspension_defiance = c("*", "1", "0", "0", "9", "1"), suspension_other = c("*",
"4", "0", "0", "2", "0")), row.names = c(NA, 6L), class = "data.frame")