Re: [R] How to exclude certain columns by column names?

2009-11-03 Thread Henrique Dallazuanna
Try this; x[,setdiff(colnames(x), 'a')] On Mon, Nov 2, 2009 at 11:31 PM, Peng Yu wrote: > I can exclude columns by column number using '-'. But I wondering if > there is an easy way to exclude some columns by column names. > >> x=cbind(c(1,2),c(3,4)) >> x >     [,1] [,2] > [1,]    1    3 > [2,]

Re: [R] How to exclude certain columns by column names?

2009-11-03 Thread Paul Hiemstra
Linlin Yan wrote: Try this: x[, colnames(x) != 'a'] And more general: x[, !colnames(x) %in% c('a','b')] Paul [1] 3 4 On Tue, Nov 3, 2009 at 9:31 AM, Peng Yu wrote: I can exclude columns by column number using '-'. But I wondering if there is an easy way to exclude some columns

Re: [R] How to exclude certain columns by column names?

2009-11-02 Thread Linlin Yan
Try this: > x[, colnames(x) != 'a'] [1] 3 4 On Tue, Nov 3, 2009 at 9:31 AM, Peng Yu wrote: > I can exclude columns by column number using '-'. But I wondering if > there is an easy way to exclude some columns by column names. > >> x=cbind(c(1,2),c(3,4)) >> x >     [,1] [,2] > [1,]    1    3 > [2,

Re: [R] How to exclude certain columns by column names?

2009-11-02 Thread Jorge Ivan Velez
Hi Peng, Here is a suggestion: subset(x, select = -a) See ?subset for more details. HTH, Jorge On Mon, Nov 2, 2009 at 8:31 PM, Peng Yu <> wrote: > I can exclude columns by column number using '-'. But I wondering if > there is an easy way to exclude some columns by column names. > > > x=cbin

[R] How to exclude certain columns by column names?

2009-11-02 Thread Peng Yu
I can exclude columns by column number using '-'. But I wondering if there is an easy way to exclude some columns by column names. > x=cbind(c(1,2),c(3,4)) > x [,1] [,2] [1,]13 [2,]24 > colnames(x)=c('a','b') > x a b [1,] 1 3 [2,] 2 4 > x[,-'a'] Error in -"a" : invalid ar