How do I hash in these 2 dataframes in R?

Viewed 28

so I have these 2 columns (genome$V9 and Impact4$INFO) from 2 different dataframes as shown below.

Basically there is a value inside each Impact4$INFO row (structure would be like OE6AXXXXXXX where X is an integer) that I want to filter in each row inside genome$V9. I understand it is complicated since there are a lot of values inside both columns...

Thank you

Column1

Column2

1 Answers

You can extract numbers from strings quite easily, when the structure is consistent. Given your structure is consistent you can try:

library(stringr)
test <- c("ID=OE6A002689", "ID=OE6A044524", "ID=OE6A057168TI")
str_extract(test, "[0-9]{6}")

Output is:

[1] "002689" "044524" "057168"

Given you want to filter your genome data based on this, you can try:

library(dplyr)
library(stringr)

ids <- str_extract(Impact4$INFO, "[0-9]{6}")

genome %>% 
  mutate(ind = str_extract(V9, "[0-9]{6}")) %>% 
  filter(ind %in% ids)

Hope that helps? Otherwise you have to provide a reproducible example (post exapmle data here).

Related