0

I have a table, let's say:

 0 4.5  12  14  24  36  47 
 6   1   1   1   7   1   3 

I want to remove the column labeled 0 if it exists in the table. The command t <- t[,!'0', with=FALSE] did not give me the desired outcome (it resulted in an error).

Pio
  • 4,044
  • 11
  • 46
  • 81
  • Where did the "with=FALSE" idea come from? As far as I know, that's only a `[.data.table` thing... It would be better if you provided a reproducible example: http://stackoverflow.com/questions/5963269 – Frank Nov 02 '13 at 22:15

2 Answers2

1

This should do the trick

> x <- setNames(c(6,1,1,1,7,1,3), c("0", "4.5", "12", "14", "24", "36", "47" ))
> x # your data
  0 4.5  12  14  24  36  47 
  6   1   1   1   7   1   3 
> x <- x[names(x) != "0"]
> x # what you want
4.5  12  14  24  36  47 
  1   1   1   7   1   3 
Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138
0

You can subtract it.

x[- which(names(x) == '0')]
John
  • 23,360
  • 7
  • 57
  • 83