从数据框架中提取行标签(?) [英] extracting row labels (?) from a data.frame
本文介绍了从数据框架中提取行标签(?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从data.frame ...开始
Starting with a data.frame...
df = data.frame(k=c(1,5,4,7,6), v=c(3,1,4,1,5))
> df
k v
1 1 3
2 5 1
3 4 4
4 7 1
5 6 5
我可能会运行一些任意操作...
I might run some number of arbitrary manipulations...
> foo1 = df[df$k>3,]
> foo2 = head(foo1[order(foo1$v),], 2)
> foo2
k v
2 5 1
4 7 1
点 foo2
以某种方式保留了 df
(在这种情况下为2和4)的原始行号。
At this point foo2
has somehow retained the original row numbers fromdf
(in this case 2 and 4).
如何提取这些?
> insert_magic_function_here(foo2)
[1] 2 4
推荐答案
p>我想你正在寻找 rownames
。
I think you're looking for rownames
.
这篇关于从数据框架中提取行标签(?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文