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

Moshe Olshansky m_olshansky at yahoo.com
Mon Jul 13 07:02:46 CEST 2009


Try A[1,,drop=FALSE] - see help("\[")

--- On Mon, 13/7/09, Weiwei Shi <helprhelp at gmail.com> wrote:

> From: Weiwei Shi <helprhelp at gmail.com>
> Subject: [R] how to keep row name if there is only one row selected from a data frame
> To: "r-help at stat.math.ethz.ch" <R-help at stat.math.ethz.ch>
> Received: Monday, 13 July, 2009, 1:55 PM
> 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
> 
> Thanks,
> 
> W.
> 
> 
> 
> -- 
> Weiwei Shi, Ph.D
> Research Scientist
> GeneGO, Inc.
> 
> "Did you always know?"
> "No, I did not. But I believed..."
> ---Matrix III
> 
>     [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org
> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>




More information about the R-help mailing list