2

data.table is very fast! However the syntax is much different. It is much like switching to ggplot from the standard base plot functions.

Code First:

library(data.table)
DT <- data.table(RF  = 1:10,
              S_1 = 11:20,
              S_2 = 21:30,
              addCol = rnorm(10)) 
bob<-as.data.frame(DT)
larry <- DT
set(DT, j = varnames, value = DT[, varnames, with = F]*DT[, RF])

Questions:

When I do run the above code, I only want to change the values in DT. However, the values in the object larry are also changed. If this is a feature, then I need help understanding how to use it. How do I stop the set command from changing both larry and DT at the same time?

IRTFM
  • 258,963
  • 21
  • 364
  • 487
hathawayj
  • 230
  • 1
  • 8
  • I'm not sure I understand the "not closing" comment. If it's a duplicate it should be closed and I would say you, Matthew, are the premier arbiter of whether it is a duplicate. I won't downvote since you say it's hard to search on, but now its main purpose in "life" is to be a target for future searches with links to answers already in the archive. – IRTFM Mar 15 '13 at 18:23
  • It is my first time posting. Feel free to close it. I do agree with Matthew on the tricky topic. On top of learning the new syntax there is also a different language/vocabulary behind it that is new (to me) as well. Once again, much like ggplot. – hathawayj Mar 16 '13 at 14:54
  • This looks like the pertinent line I was looking for from the above link. DT3 <- copy(DT) rather than DT3 <- DT will keep it functioning like base R. – hathawayj Mar 16 '13 at 15:01
  • @DWin That's strange, where's my not closing comment gone. Don't remember deleting it. Anyway, I would have meant it the sense "I am voting to close this. Not because it's bad but because it's a duplicate." (Trying to be gentle to the OP's first question.) Completely agree. – Matt Dowle Mar 20 '13 at 13:34

0 Answers0