I am not a pro, so please excuse my messy code, however, I cannot solve this error I keep getting. I am trying to pull data from a different table (CompMeta) to annotate the 'company category' based on the 'company name' using a for loop and grep.
I used the following code in R:
for (i in 1:length(df5$Company1)) {
df5$type[i] <- CompMeta$`Company Category`[grep(df5$Company1[i],CompMeta$Company)]
}
Unfortunately I am getting this error and can't really figure out why:
Error in df5$type[i] <- CompMeta$`Company Category`[grep(df5$Company1[i], :
replacement has length zero
If I just test it with a number instead of i, the grep function works fine! Would be really great if someone could help me out here!
Best Talata