Note that there are some explanatory texts on larger screens.

plurals
  1. POData.table assign value to existing column
    primarykey
    data
    text
    <p>I am performing an apparently simple assignment in a data.table object.</p> <pre><code>library(RODBC) library(data.table) library(ffbase) library(plyr) library(doBy) library(reshape2) ST_a = Sys.Date()-7 ST = paste("'",as.character(format(ST_a,"%d.%m.%Y")),"'",sep="") rd_a = Sys.Date()- 41 rd = paste("'",as.character(format(rd_a,"%d.%m.%Y")),"'",sep="") ch&lt;-odbcConnect("db",uid="user",pwd="psw") chunks &lt;- c(seq.Date(from=rd_a, to=ST_a, by = 20),ST_a) started.at &lt;- proc.time() Sys.sleep(1) memory.limit(size=4095) for (i in 1:(length(chunks)-1)){ start &lt;- paste("'",as.character(format(chunks[i],"%d.%m.%Y")),"'",sep="") end &lt;- paste("'",as.character(format(chunks[i+1],"%d.%m.%Y")),"'",sep="") query &lt;- paste("Select * from DATA_LOCAL_V where id='EHPFCMO' and timestamp&gt;",rd," and reference_date&gt;=",start," and reference_date&lt;",end,sep="") EHPFC.ck &lt;- data.table(sqlQuery(ch,query,stringsAsFactors=FALSE)) EHPFC.ck[,TIMESTAMP:=TIMESTAMP-60^2] EHPFC.ck[, pod:=7] EHPFC.ck[as.POSIXlt(EHPFC.ck$TIMESTAMP)$hour %in% c(20:23), pod:=23] EHPFC.ck[as.POSIXlt(EHPFC.ck$TIMESTAMP)$hour %in% c(8:19), pod:=19] EHPFC.ck[,day:=as.Date(trunc(TIMESTAMP))] EHPFC.ck[,TIMESTAMP:=NULL] EHPFC.ck &lt;- EHPFC.ck[,mean(VALUE),by=list(ID,REFERENCE_DATE,day,pod)] setnames(EHPFC.ck,"V1","price") EHPFC.ck &lt;- as.ffdf(EHPFC.ck) if (i==1){ EHPFC &lt;- EHPFC.ck } else { EHPFC &lt;- ffdfappend(EHPFC,EHPFC.ck[,]) } rm(EHPFC.ck) gc() } EHPFC &lt;- data.table(EHPFC[,]) EHPFC &lt;- orderBy(~day+pod+REFERENCE_DATE, data=EHPFC) a &lt;- c(0,log(EHPFC[-1,price]/EHPFC[-nrow(EHPFC),price])) EHPFC &lt;- EHPFC[,RoR:=a] </code></pre> <p>By doing that I get the following error msg:</p> <pre><code>error in `[.data.table`(EHPFC, , `:=`(RoR, a)) : At an earlier point, this data.table has been copied by R. Avoid key&lt;-, names&lt;- and attr&lt;- which in R currently (and oddly) all copy the whole data.table. Use set* syntax instead to avoid copying: setkey(), setnames() and setattr(). If this message doesn't help, please ask on datatable-help. </code></pre> <p>The object EHPFC looks like the following:</p> <pre><code>EHPFC ID REFERENCE_DATE day pod price RoR [1,] EHPFCMO 2012-10-27 2012-10-27 7 35.34625 0 [2,] EHPFCMO 2012-10-28 2012-10-27 7 35.34625 0 [3,] EHPFCMO 2012-10-29 2012-10-27 7 35.34625 0 [4,] EHPFCMO 2012-10-30 2012-10-27 7 35.34625 0 [5,] EHPFCMO 2012-10-31 2012-10-27 7 35.34625 0 </code></pre> <p>I am a bit confused why this is happening.</p> <p>Any idea? Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload