I have a data frame and want to filter it based on the partial match of names in the first column with the names in the vector.
nam <- c('mmu_mir-1-3p','mmu_mir-1-5p','mmu-mir-3-5p','mir-4','mmu-mir-6-3p') #factor
aa <- c('12854','36','5489','54485','2563') #numeric
df <- data.frame(nam,aa)
vector <- c('mir-1','mir-3','mir-6')
I need to have rows in the new data frame where names in df$nam
are partially matching with the names in vector
. So new_df
should look like this.
new_nam <- c('mmu_mir-1-3p','mmu_mir-1-5p','mmu-mir-3-5p','mmu-mir-6-3p') #factor
new_aa <- c('12854','36','5489','2563') #numeric
new_df <- data.frame(new_nam,new_aa)