I have a vector
a <- c("there and", "walk and", "and see", "go there", "was i", "and see",
"i walk", "to go", "to was")
and a data frame bg where
bg <- data.frame(term=c("there and", "walk and", "and see", "go there", "was i", "and see",
"i walk", "to go", "to was"), freq=c(1,1,2,1,1,2,1,1,1))
I need to create a vectorized version for the following code using either sapply,tapply, or vapply or apply etc
d <- NULL
for(i in 1:length(a)){
temp <- filter(bg,term==a[i])
d <- rbind(d,temp)
}
The need is search the bg data when term==a[i]
and create a data frame d
I need a vector version as for loops are excruciatingly slow in R.
Here is the sample data
> bg
term freq
1 there and 1
2 walk and 1
3 and see 2
4 go there 1
5 was i 1
6 and see 2
7 i walk 1
8 to go 1
9 to was 1
and
>d
term freq
1 there and 1
2 walk and 1
3 and see 2
4 and see 2
5 go there 1
6 was i 1
7 and see 2
8 and see 2
9 i walk 1
10 to go 1
11 to was 1
Thanks