我有一个data.frame,其中一列包含一些标记为“Blank”的值。
amount <- c(10,12,14)
description <- c("bankafschrift", "ABN", "albert heijn")
post <- ("Blank", "Bank", "Blank")
df <- data.frame(description, amount, post)
我现在想在所有标记为“空白”的值上编写循环,并手动为其提供输入。
因此,我写了以下内容: for(i in 1:nrow(df)) {
if (df$post == "Blank") {
des <- df$description[i]
var <- paste0("What is the post of: ", des)
df$post[i] <- readline(var)
}
}
它适用于第一行,但后来我收到以下错误:
Warning messages:
1: In if (df$post == "Blank") { :
the condition has length > 1 and only the first element will be used
2: In if (df$post == "Blank") { :
the condition has length > 1 and only the first element will be used
3: In if (df$post == "Blank") { :
the condition has length > 1 and only the first element will be used
任何人都可以详细说明出了什么问题以及错误究竟意味着什么?