I would like to take back some indexes using a for loop and right now, the loop returns only NAs.
df <- data.frame(v1 = c("a", "b", "c", "d", "e"),
v2 = c("f", "g", "h", "i", "j"),
v3 = c("aa", "bb", "cc", "bb", "dd"))
vec <- c("aa", "bb", "ee")
res <- list()
for (i in(vec)){
temp <- vec[i]
res[[i]] <- grep(temp, df[,3])
}
gives
res
$aa
[1] NA NA NA NA NA
$bb
[1] NA NA NA NA NA
$ee
[1] NA NA NA NA NA
while I am struggling for this
res
$aa
[1] 1
$bb
[1] 2 4
$ee
[1]
What is this very simple thing that I keep being unaware of?