在哪个列中有特定变量的值
我有此数据框:
a <- c(2,5,90,77,56,65,85,75,12,24,52,32)
b <- c(45,78,98,55,63,12,23,38,75,68,99,73)
c <- c(77,85,3,22,4,69,86,39,78,36,96,11)
d <- c(52,68,4,25,79,120,97,20,7,19,37,67)
e <- c(14,73,91,87,94,38,1,685,47,102,666,74)
df <- data.frame(a,b,c,d,e)
此变量:
bb <- 120
我需要知道变量“ BB”值的DF的列号。我该怎么办? 所有大家!
I have this dataframe:
a <- c(2,5,90,77,56,65,85,75,12,24,52,32)
b <- c(45,78,98,55,63,12,23,38,75,68,99,73)
c <- c(77,85,3,22,4,69,86,39,78,36,96,11)
d <- c(52,68,4,25,79,120,97,20,7,19,37,67)
e <- c(14,73,91,87,94,38,1,685,47,102,666,74)
df <- data.frame(a,b,c,d,e)
and this variable:
bb <- 120
I need to know the column number of df in which there is the value of the variable "bb". How can I do?
Thx everyone!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们可以使用
使用
带有arr.ind = true
在创建逻辑矩阵后提取行/col索引。然后,提取第二列以获取列索引,如果列中有重复的元素以进行比较,请用
unique
包装以返回唯一的列索引We could use
which
witharr.ind = TRUE
to extract the row/col index after creating a logical matrix. Then, extract the second column to get the column indexIf there are duplicate elements in the column for the value compared, wrap with
unique
to return the unique column index我认为我们可以使用
grep
I think we could use
grep