Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using `:=` from data.table when data.table package is not loaded?

I want to use := operator from data.table without loading data.table. For example for the following data.table, I want to add another column called error:

DT <- data.table::data.table(station = rep(1:1,52560), mod = rnorm(1*52560),obs = rnorm(1*52560))

If I do the following everything goes well, however, I am puzzled how it worked without referring to package data.table (the data.table library is not loaded)?!!

DT[ , `:=`(error  = mod - obs)]

How can I rewrite the above line using data.table::::= ?!!

like image 355
newbie Avatar asked Feb 12 '16 00:02

newbie


People also ask

What is data table package?

Data. table is an extension of data. frame package in R. It is widely used for fast aggregation of large datasets, low latency add/update/remove of columns, quicker ordered joins, and a fast file reader. The syntax for data.

What is dt package in R?

The R package DT provides an R interface to the JavaScript library DataTables. R data objects (matrices or data frames) can be displayed as tables on HTML pages, and DataTables provides filtering, pagination, sorting, and many other features in the tables.

Where will you find the data table function?

On the Data tab, click What-If Analysis > Data Table (in the Data Tools group or Forecast group of Excel 2016).


1 Answers

Not sure I understand correctly, but regarding :

I am going to use this in another package and preferably I want not to load data.table. – newbie

I am importing the package, I have no other choice since data.table will not work if I do not import. Would importing alone take care of this? – newbie

Yes Import data.table rather than Depend on it from your package. You may have tried that and it didn't work because of this common issue. See solution here :

Using data.table package inside my own package

like image 180
Matt Dowle Avatar answered Oct 22 '22 18:10

Matt Dowle