[R] Remove Columns by Name from zoo object
Sean Carmody
seancarmody at gmail.com
Mon Nov 10 23:12:52 CET 2008
Perfect, works like a charm. Thanks Gabor.
Sean.
On Mon, Nov 10, 2008 at 11:35 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> On Mon, Nov 10, 2008 at 12:31 AM, Sean Carmody <seancarmody at gmail.com> wrote:
>> The tricks for removing columns specified by name from data frames such as
>>
>> x$mycol <- NULL
>
> That only works for data frames since they are based on
> lists but not for objects like matrix, ts and zoo which are not
> based on lists. Try this:
>
> library(zoo)
> z <- zoo(cbind(a = 1:2, b = 3:4, c = 5:6))
> # all but b
> z <- z[, colnames(z) != "b"]
> z
>
> z <- zoo(cbind(a = 1:2, b = 3:4, c = 5:6))
> # all but b and c
> z <- z[, ! colnames(z) %in% c("b", "c")]
> z
>
--
Sean Carmody
The Stubborn Mule
http://www.stubbornmule.net
http://twitter.com/seancarmody
More information about the R-help
mailing list