[R] How to replace match words whith colum name of data frame?
θ ”
yarmi1224 at hotmail.com
Sat Jul 1 09:43:43 CEST 2017
I have two data frame. I want to use "chemical_df" to match "concept_df "
concept_df <- data.frame(concept=c("butan acid ", "nano diamond particl", "slurri
composit", "composit ph polis", " inorgan particl ", "grind liquid", "liquid formul", "nanoparticl", "size abras particl", "agent malic acid"))
chemical_df <- data.frame(chemical=c("basic", "alkalin", "alkali", "acid", " ph ", "hss"))
Here is my match code:
library(magrittr)
match_df <- NULL
for (i in 1:length(chemical_df$chemical)) {
match_df<-data.frame(category=concept_df[grep(chemical_df$chemical[i], concept_df$concept), ] ) %>%
rbind(match_df)
}
But I don't want this result:
concept category
1 butan acid butan acid
2 nano diamond particl
3 slurri composit
4 composit ph polis composit ph polis
5 inorgan particl
6 grind liquid
7 liquid formul
8 nanoparticl
9 size abras particl
10 agent malic acid agent malic acid
I desire to get :
concept category
1 butan acid chemical
2 nano diamond particl
3 slurri composit
4 composit ph polis chemical
5 inorgan particl
6 grind liquid
7 liquid formul
8 nanoparticl
9 size abras particl
10 agent malic acid chemical
Is any way to solve it?
[[alternative HTML version deleted]]
More information about the R-help
mailing list