[英]Look up data in a column based on a value in another column, same row
I have a dataframe that has 6 columns (AF) and over 200K rows.我有一个包含 6 列 (AF) 和超过 200K 行的数据框。 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.我想在 B 列(命名词)中查找一个字符串,并在另一列 D(tf 值)中找到它对应的值,请在同一行。
For example I want the output to be:例如,我希望输出为:
Word: encryption, tf: 0.009041.字:加密,tf:0.009041。
I rather not use a loop, but if needed I am open to suggestions, as the df is large.我宁愿不使用循环,但如果需要,我愿意接受建议,因为 df 很大。 Thank you very much for your time.非常感谢您的宝贵时间。
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'.这将创建一个仅包含列 tf 和 Word 值为“加密”的行的数据框。 If you wanted the rows containing any one of a set of words in either the columns Class or Word, you could do this:如果您想要包含 Class 或 Word 列中的一组单词中的任何一个的行,您可以这样做:
library(dplyr)
wordset <- c('hockey','encryption')
tf <- yourdata %>%
filter(Class %in% wordset | Word %in% wordset) %>%
select(tf)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.