Question on writing a function to look up a text string on a data.table
My data look like this:
word1 word2 frequency
1 thanks_for the 247
2 one_of the 177
3 if_you dont 168
4 all_the time 164
5 to_get to 156
6 to_see you 152
I wrote this code to find a match in the word1 column, then next output the Corresponding word2.
firstword <- dat1[word1=="one_of"]
nextword <- firstword[ ,word2]
nextword
which returns
"the" "my" "them" "your"
Next I tried to write a function that accomplishes this.
predictword <- function(word1,dat){firstword <- dat[word1==word1]
nextword <- firstword[ ,word2]
nextword}
When I ran this function
predictword("one_of", dat1)
I will get 1000 lines of “”
[1] " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " "
…
…
[932] " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " "
[951] " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " "
[970] " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " "
[989] " " " " " " " " " " " " " " " " " " " " " " " "
[ reached getOption("max.print") -- omitted 21138 entries ]
What is going on? How can I get my function to return just a few words, like when I typed the words in my code?