I have a word table (wt) like this (3 by 3 )
ungrateful mango uncertain
hobby prejudicial meat
persecution bird honest
and a word dictionary (dict)
persecution
overpowering
prejudicial
offense
ungrateful
uncertain
musical
murderous
detest
youth
I want to search all words in the wt with the dict and if any word match with the dictionary, that will give the dictionary word position in the word table, and the words which do not match will be automatically deleted.
wt <- matrix(c("ungrateful","mango", "uncertain","hobby", "prejudicial", "meat","persecution","bird","honest"), nrow = 3, ncol = 3, byrow = TRUE)
dict<- matrix(c(
"persecution",
"overpowering",
"prejudicial",
"offense",
"ungrateful",
"uncertain",
"musical",
"murderous",
"detest",
"youth"), nrow = 10, ncol = 1, byrow = FALSE)
for (i in 1:nrow(df)){
for (i in 1:col(df)){
x[i,j ] <- charmatch(df[i,j],dict_word)
}
}
But this is giving error, when I am expecting output like this
[,1] [,2] [,3]
[1,] 5 6
[2,] 3
[3,] 1
I am pretty new in R and don't have good idea about the syntax . please help.