[datatable-help] create empty data.table
Frank Erickson
fperickson at wisc.edu
Thu Jul 23 14:53:20 CEST 2015
You can make a wrapper for something like
> DT <- data.table(date=Sys.Date()[0],id=character(0),value=numeric(0))
# examine structure
> str(DT)
Classes ‘data.table’ and 'data.frame': 0 obs. of 3 variables:
$ date :Class 'Date' num(0)
$ id : chr
$ value: num
- attr(*, ".internal.selfref")=<externalptr>
# try appending
> str(rbind(DT,list(Sys.Date(),"A",1)))
Classes ‘data.table’ and 'data.frame': 1 obs. of 3 variables:
$ date : Date, format: "2015-07-23"
$ id : chr "A"
$ value: num 1
- attr(*, ".internal.selfref")=<externalptr>
--Frank
On Thu, Jul 23, 2015 at 5:51 AM, statquant3 <statquant at outlook.com> wrote:
> I wanted to create a function that creates an empty data.table with
> specified
> column types.
> emptyDT <- function(colNames,colTypes){...}
> I would call
> emptyDT(c('date','id','value'),c('Date','Character','Numeric'))
>
> Is there something available for this already ?
>
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/create-empty-data-table-tp4710237.html
> Sent from the datatable-help mailing list archive at Nabble.com.
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20150723/271cd332/attachment.html>
More information about the datatable-help
mailing list