使用循環和條件語句,我想確定有超過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