Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude one column from data.table OR convert to data.table to MTS

Tags:

r

data.table

zoo

When using data.table is it possible to return all the columns except one, like in data.frame?

If the answer is no, does anyone have an elegant way to transform a multiple time series data.table to a zoo or other time series object?

Consider the following example:

library(data.table) library(zoo)  ## DEFINE DATA set.seed(1) dt = data.table(     mydates = as.Date("2012-01-01") + 1:9,      value1 = sort(rpois(9, 6)),     value2 = sort(rpois(9, 6)),     value3 = sort(rpois(9, 6)),     value4 = sort(rpois(9, 6)),     value5 = sort(rpois(9, 6)))  ## CONVERT TO DATA FRAME df = as.data.frame(dt)  ## CONVERT TO ZOO zooObj = zoo(df[,-1], df$mydates)  ## EXAMPLE OF DESIRED RESULTS plot(zooObj, col=1:ncol(zooObj)) 

How would I do that without df = as.data.frame(dt)?

like image 476
geneorama Avatar asked Aug 20 '12 22:08

geneorama


1 Answers

Try with=FALSE :

dt[,-1,with=FALSE] 

As an aside, feature request #416 is related :

Add not join DT[-J(...)], and not columns DT[,-"colC",with=FALSE].

like image 148
Matt Dowle Avatar answered Sep 28 '22 17:09

Matt Dowle