Skip to content
Prev 304625 / 398503 Next

apply --> data.frame

do.call/rbind appeared to be TRT. I tried it and got a data frame with
list columns (instead of vectors);

as.data.frame(do.call(rbind,lapply(list.files(...), function (name) {
    ....
    c(name,list(num1,num2,num3), # num* come from some calculations above
      strsplit(sub("[^-]*(train|test)[^-]*(-(S)?pca([0-9]*))?-s([0-9]*)c([0-9.]*)\\.score",
                   "\\1,\\3,\\4,\\5,\\6",name),",")[[1]])
  })), stringsAsFactors = FALSE)

'data.frame':	2 obs. of  8 variables:
 $ file        :List of 2
  ..$ : chr "zzz_test_0531_0630-Spca181-s0c10.score"
  ..$ : chr "zzz_train_0531_0630-Spca181-s0c10.score"
 $ lift.quality:List of 2
  ..$ : num 0.59
  ..$ : num 0.621
 $ proficiency :List of 2
  ..$ : num 0.0472
  ..$ : num 0.0472
 $ set         :List of 2
  ..$ : chr "test"
  ..$ : chr "train"
 $ scale       :List of 2
  ..$ : chr "S"
  ..$ : chr "S"
 $ pca         :List of 2
  ..$ : chr "181"
  ..$ : chr "181"
 $ s           :List of 2
  ..$ : chr "0"
  ..$ : chr "0"
 $ c           :List of 2
  ..$ : chr "10"
  ..$ : chr "10"

I guess the easiest way is to replace c(...list()...) with c(...) but
that would mean converting num1,num2,num3 to string and back which I
want to avoid for aesthetic reasons. Any better suggestions?

thanks a lot!