Remove multiple columns from data.table

This looks like a solid, reproducible bug. It’s been filed as Bug #2791. It appears that repeating the column attempts to delete the subsequent columns. If no columns remain, then R crashes. UPDATE : Now fixed in v1.8.11. From NEWS : Assigning to the same column twice in the same query is now an error … Read more

How to get week numbers from dates?

Base package Using the function strftime passing the argument %V to obtain the week of the year as decimal number (01–53) as defined in ISO 8601. (More details in the documentarion: ?strftime) strftime(c(“2014-03-16”, “2014-03-17″,”2014-03-18”, “2014-01-01”), format = “%V”) Output: [1] “11” “12” “12” “01”

When should I use the := operator in data.table?

Here is an example showing 10 minutes reduced to 1 second (from NEWS on homepage). It’s like subassigning to a data.frame but doesn’t copy the entire table each time. m = matrix(1,nrow=100000,ncol=100) DF = as.data.frame(m) DT = as.data.table(m) system.time(for (i in 1:1000) DF[i,1] <- i) user system elapsed 287.062 302.627 591.984 system.time(for (i in 1:1000) … Read more

dplyr on data.table, am I really using data.table?

There is no straightforward/simple answer because the philosophies of both these packages differ in certain aspects. So some compromises are unavoidable. Here are some of the concerns you may need to address/consider. Operations involving i (== filter() and slice() in dplyr) Assume DT with say 10 columns. Consider these data.table expressions: DT[a > 1, .N] … Read more

Split text string in a data.table columns

Update: From version 1.9.6 (on CRAN as of Sep’15), we can use the function tstrsplit() to get the results directly (and in a much more efficient manner): require(data.table) ## v1.9.6+ dt[, c(“PX”, “PY”) := tstrsplit(PREFIX, “_”, fixed=TRUE)] # PREFIX VALUE PX PY # 1: A_B 1 A B # 2: A_C 2 A C # … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)