try
test <- subset(test, select = -c(Y))
The key is the minus sign before c() in the select argument.
You can put in as many columns as you like.
-a
On Feb 23, 2010, at 11:02 AM, David Winsemius wrote:
>
> On Feb 23, 2010, at 6:04 AM, Knut Krueger wrote:
>
>> Hi to all,
>> test <- data.frame("X"=c(1:4),"Y"=c(5:8),"Z"=c(8:11))
>> test <- test[,-2]
>>
>> Is there a way to specify the col name "Y" to delete instead the number?
>>
>
> I believe that negative indexing only works with numeric arguments. You could
> dummy up a negation approach for character vectors with:
>
> > test[, !(names(test) %in% c("Y"))] #non-negated logical vector to index
> X Z
> 1 1 8
> 2 2 9
> 3 3 10
> 4 4 11
>
> > test[, -grep("Y",names(test))] # negated numeric vector to index
> X Z
> 1 1 8
> 2 2 9
> 3 3 10
> 4 4 11
>
> --
> David
>> Kind regards Knut
>>
>> ______________________________________________
>> [email protected] 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.
>
> ______________________________________________
> [email protected] 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.
The information contained in this message may be privile...{{dropped:17}}
______________________________________________
[email protected] 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.