简体   繁体   English

根据另一列同一行中的值查找列中的数据

[英]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.

相关问题 根据R中同一行的另一列中的单元格的值对一列求和 - Sum a column based on the value of a cell in another column of the same row in R 如何使用 dplyr 在上一行的同一列中查找计算值? - How to use dplyr to look up a calculated value in the same column one row above? 如何根据行和列在R中查找值 - How to look up values in R based on row and column 如何在矩阵(R)中查找行/列组合的值? - How to look up the value of a row/column combination in a matrix (R)? R - 如何基于来自同一行的另一列的值从列获取值 - R - How to get value from a column based on value from another column of same row 如何根据同一行另一列的最高值从 1 列中获取值? - How do I get the value from 1 column based on highest value of another column of the same row? 如何根据另一列的百分位数查找值 - How to look up a value according to percentile of another column 根据该行的另一列中的值对列中的值进行操作的更好方法? - Better way to operate on a value in a column based on the value in another column of that row? 根据另一行中另一列的值将列添加到数据框 - Add column to data frame based on values of another column in another row 根据同一列的另一行中的值在一行中设置 FlexTable 颜色,并在所有列中执行此操作 - Set FlexTable color in a row based on the value in another row of the same column and do this across all columns
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM