使用循环和条件语句,我想确定有超过2.50循环和条件语句
customer <- c("john", "amy", "doug")
product <- c("coffee", "pastry", "pastry")
store <- c("a", "b", "c")
cost <- c(5.50, 2.45, 3.00)
df <- data.frame(customer, product, store, cost)
的值,我想找出超过$ 2.50购买并保存“存储”和“产品”作为行与这些购买相关的独立媒介超过2.50美元。
到目前为止,这是我的代码,它是不工作...
for (row in 1:nrow(df)) {
customer <- df[row, "customer"]
product <- df[row, "product"]
store <- df[row, "store"]
cost <- df[row, "cost"]
if(cost > 2.50) {
print(paste(customer, "purchased", product, "at", store, "for", cost))
}
}
这不是工作,以及如何保存这两个“产品”和“存储”作为单独的载体?
为什么你需要保存它们? – Elin