apply --> data.frame
* David Winsemius <qjvafrzvhf at pbzpnfg.arg> [2012-08-30 10:14:34 -0700]:
str( as.data.frame( do.call(rbind, strsplit(c("a,1","b,2","c,3"),
",") ) , stringsAsFactors=FALSE) ) 'data.frame': 3 obs. of 2 variables: $ V1: chr "a" "b" "c" $ V2: chr "1" "2" "3"
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!
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://jihadwatch.org http://thereligionofpeace.com http://palestinefacts.org http://ffii.org http://pmw.org.il I don't have an attitude problem. You have a perception problem.