[R] how to keep row name if there is only one row selected from a data frame

hadley wickham h.wickham at gmail.com
Mon Jul 13 07:53:17 CEST 2009


On Mon, Jul 13, 2009 at 5:55 AM, Weiwei Shi<helprhelp at gmail.com> wrote:
> Hi, there:
>
> Assume I have a dataframe with rownames like A with rownames like a to e,
>
>> A
>  [,1] [,2]
> a    1    6
> b    2    7
> c    3    8
> d    4    9
> e    5   10
>
> when I use A[1,], I lost the rowname for it, like below. How could I keep
> it? Is there an easy way instead that I have to modify by myself after I
> used A[1,] manually.
>
>> A[1,]
> [1] 1 6

I think if you do str(A) you'll discover it's a matrix, not a data frame.

Hadley

-- 
http://had.co.nz/




More information about the R-help mailing list