I have downloaded data from lending club and loaded it into R using data.table's fread() function.
For each row, I would like data.table to collect all of the information from all of the columns and put it into a single string, in the most efficient manner possible. My current function works, but think that this is probably quite slow and could deal with some improvement from some data.table experts on SO.
foo <- function(y, dt_obj, col_names=colnames(dt_obj)){
paste0("http://localhost:8080/predict?",
paste0(col_names,"=",unlist(dt_obj[y,],use.names=FALSE),
collapse="&")
)
}
In the above function, y is the row number, the dt_obj is the csv data that was read into R using fread.
I then go through each row and add in the data to my original data.table object dt using the following line
dt[,strg:=sapply(seq(nrow(dt)),function(x){foo(x,dt_obj=dt)})]
However this seems to take a while and believe that the speed could be improved if a more efficient foo function were created or data.table was used in a more efficient manner...
As always any help would be greatly appreciated...