I have a data frame and a list of 50 elements that I need to compare and create another list with existing and not existing data in the df:
POS | WORD | TRANSLATION | LEMMA |
---|---|---|---|
PRON | мин | I | |
PRON | кини | he, she | |
PRON | олор | it inanimate | |
PART | суох | no | |
ADV | манна | here | |
CCONJ | уонна | and |
List:
[[1]]
[1] "мин"
[[2]]
[1] "биирдэ"
[[3]]
[1] "манна"
[[4]]
[1] "сааспар"
[[5]]
[1] "уонна"
If the word from the list IS IN the DF, then return POS, WORD, LEMMA If NOT in the DF, then return "- WORD -"
This is what I have so far:
test <- list()
for (w in 1:length(pron$WORD)) {
for (i in 1:length(sakha_text_50)) {
if(sakha_text_50[i] == pron$WORD[w])
print(test[[length(test) + 1]] <- paste(pron$POS[w], ":", pron$WORD[w], ":", pron$LEMMA[w]))
}
}
However, when I write something like this, it prints everything, even what is in the list. What could be a problem?
test <- list()
for (w in 1:length(pron$WORD)) {
for (i in 1:length(sakha_text_50)) {
if(sakha_text_50[i] == pron$WORD[w])
print(test[[length(test) + 1]] <- paste(pron$POS[w], ":", pron$WORD[w], ":", pron$LEMMA[w]))
if(sakha_text_50[i] != pron$WORD[w]) {
print(test[[length(test) + 1]] <- paste("-", ":", sakha_text_50[i], ":", "-"))}
}
}
The output should be something like:
"PRON : мин : "
"- : биирдэ: -"
"ADV: манна: "
"- : сааспар: -"
Aucun commentaire:
Enregistrer un commentaire