I am trying to calculate the total price for China and US location using for loop :
Please refer below sample data-frame and code :
z <- data.frame(location = c("china", "china", "US", "US" ), quantity = c(100, 200, 100, 200))
## Calculate Total price, considering price for one quanity is $1 for china and $3 for US
for row in 1:nrow(z) {
l <- z[row, "location"]
q <- z[row, "quanity"]
ifelse (l == "china",
z$total <- (z$quantity * 1),
z$total <- (z$quantity * 3))