Message-ID: <CAP5QEc5Z_GhHW+66u__9nKxpP8BkoypDXM-Jz1xy7Qj5vgwXcg@mail.gmail.com>
Date: 2016-04-16T00:58:43Z
From: Paul Tremblay
Subject: faster way to use filter this
I have the following (simplified) vectors:
index <- c("shoe" "shirt" "fruit")
cost <- c(100, 50, 2)
data <- c("shirt", "shoe", "vegetable")
I want my outcome to be:
(50, 100, 0)
(shirt => 50, shoe => 100, vegetable => not found, so 0)
I have written the following function:
for (i in custom_list) {
+ this_cost <- cost[index == i]
+ message(this_cost)
+ }
This gives me (50, 100)
I haven't figured out how to use the ifelse. But more importantly, I think
there should be an easier, and faster way to do this with vectors?
Thanks!
Paul
[[alternative HTML version deleted]]