-1

I have a dataframe that has 6 columns (A-F) and over 200K rows. I would like to look up a string in a column B (named word), and find its corresponding value in another column D(tf value), same row, please.

For example I want the output to be:

Word: encryption, tf: 0.009041.

I rather not use a loop, but if needed I am open to suggestions, as the df is large. Thank you very much for your time.

Shawn
  • 139
  • 1
  • 3
  • 9
  • 2
    (1) Please do not post an image of code/data/errors: it cannot be copied or searched (SEO), it breaks screen-readers, and it may not fit well on some mobile devices. Ref: https://meta.stackoverflow.com/a/285557/3358272 (and https://xkcd.com/2116/). (2) Your description of how to select the row is not clear, please elaborate. For some guidance on how to well ask your question, please scan through one or more of: https://stackoverflow.com/questions/5963269, https://stackoverflow.com/help/mcve, and https://stackoverflow.com/tags/r/info. – r2evans Feb 28 '19 at 21:55
  • Thank you for your guidance. I edited the question to better reflect my inquiry, and removed the image from my own dataframe. – Shawn Mar 01 '19 at 17:39
  • I think you missed one of the salient points, Shawn. An image of data is bad. No data at all is worse. *"I need my dataframe to be transformed from to "* is not a good way to solicit help. ***Please*** read the links I provided; they are not my being lazy or snotty, those happen to be succinct and well-accepted norms for how to ask well your question and improve the likelihood of getting a relevant answer, more quickly. In the future, your change of getting a good answer is high if you do it all the first time, while it's still "new" on the list of questions. – r2evans Mar 01 '19 at 20:59

1 Answers1

0

It could be that I don't understand the question, but is this what you want?

library(dplyr)
tf <- yourdata %>%
    filter(Word == 'encryption') %>%
    select(tf)

That would create a data frame containing only the column tf and only rows for which the value of Word is 'encryption'. If you wanted the rows containing any one of a set of words in either the columns Class or Word, you could do this:

library(dplyr)
wordset <- c('hockey','encryption')
tf <- yourdata %>%
    filter(Class %in% wordset | Word %in% wordset) %>%
    select(tf)
ericOss
  • 171
  • 5
  • Yes, this is it exactly. Thank you very much for your assistance. – Shawn Mar 01 '19 at 17:32
  • Shawn: though not a requirement, it is customary on StackExchange sites that when one or more answers are acceptable, please [accept one of them](https://stackoverflow.com/help/someone-answers); doing so not only provides a little perk to the answerer with some points, but also provides some closure for readers with similar questions. Though you can only accept one answer, you have the option to up-vote as many as you think are helpful. (If there are still issues, you will likely need to edit your question with further details.) – r2evans Mar 03 '19 at 13:38