[R] how to keep row name if there is only one row selected from a data frame
R. Michael Weylandt
michael.weylandt at gmail.com
Wed Nov 23 15:45:58 CET 2011
You probably mean this:
df1[!(rownames(df1) %in% c("2098","2970","784")), ]
Remember, row names are strings: if you give R an integer, it will
interpret it as a row index.
Michael
On Wed, Nov 23, 2011 at 5:37 AM, agent dunham <crosspide at hotmail.com> wrote:
> Dear Community,
>
> I'm having a similar problem. I'm working with the data.frame attached (
> http://r.789695.n4.nabble.com/file/n4099139/df1.xls df1.xls ), let's call it
> df1 (and when I type str(df1) it answers data.frame)
>
> df1 has its own rownames (In the .xls the column "id", not 1,2,3, ...), and
> its dimension is 80x7
>
> I'd like to drop rows by their rownames; in fact I'd like to drop rows
> "2098", "2200" and "784" How can I do it?
>
> I've tried:
>
> a) df2outliers <- df1 %in% (2098,2970,784)
>
> b) df1<- df1[-2098, , drop= TRUE]
>
> But it seems rows are undefined. However when I uploaded this .xls I typed:
>
> df1<- read.xls("C:/... dir .../df1.xls",colNames= TRUE, *rowNames= TRUE*)
>
> Why do I loose rownames although I said rowNames= TRUE ? user at host.com
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/how-to-keep-row-name-if-there-is-only-one-row-selected-from-a-data-frame-tp895594p4099139.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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