📌  相关文章
📜  r - 检查列是否具有非数字值 - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:29.893000             🧑  作者: Mango

代码示例1
df <- data.frame(list(A=c(1, 2, 3, 4, 5, 6, 7, 8, 9), B=c("40g", "< 2", "thx", "about 1", "1-2", "1/2", 3, 2.3, "two")))
df$B <- as.character(df$B)

myscan <- function(x) {
 new <- vector("numeric",length(x))
 for(i in seq_along(x)) {
   new[i] <- readline(sprintf("Non numeric entry '%s' new value to set: ",x[i]))
 }
 as.numeric(new)
}

# get the entries 
notNum <- is.na( as.numeric(df$B) )
# Loop and ask for updates
df$B[notNum] <-  myscan(df$B[notNum])