-5

This is sort of a duplicate of this question, but the emphasis is very different, so I'm posting it.

I have a data.frame with one column. If I attempt to delete a row using "df[-1, ]" R returns a List. How do I get it to return a data.frame?

Community
  • 1
  • 1
Greg Dougherty
  • 3,281
  • 8
  • 35
  • 58
  • 2
    I don't think the minus sign qualifies as a "very different" emphasis – Pierre L Jan 05 '16 at 20:16
  • 2
    That is an identical dupe. Thanks saving as the time looking for it ourselves. – David Arenburg Jan 05 '16 at 21:01
  • No, it isn't, because if it was a dupe, then a search for "How do I delete rows from a data frame when the DF only has one column" would find it. Which it didn't. It only came up when I did that as a title. – Greg Dougherty Jan 05 '16 at 23:49

1 Answers1

0

The problem is that R is trying to be "helpful", and simplifying your data for you. The solution is to do the following (note two commas, not one):

df[-1,, drop = FALSE]

This will remove the specified row, and leave your data.frame otherwise untouched.

Greg Dougherty
  • 3,281
  • 8
  • 35
  • 58