[R] Fwd: filter out many data.frames
Uwe Ligges
ligges at statistik.uni-dortmund.de
Sun May 16 15:10:58 CEST 2004
Christian Schulz wrote:
> Yes, i have recognized my stupid approach.
> Now it works but any help how i get
> the names in tList from the expand.grid combinaton's instead
> number from 1:64 would like great!
>
> Thanks Christian
>
>
>
> data <- expand.grid(class02 = c("A","B","C","D"), class04 =
> c("A","B","C","D"),PREDICT = c("A","B","C","D"))
> tList <- vector("list", numeric(length(data)))
No. I told you to use vector(nrow(data), mode = "list").
length(data) equal 3 in your case, and numeric(3) is 0, hence you get an
empty list. But you want to get one intitialized with 64 elements!
Furthermore, I told you that there are better ideas than calling an
object "data".
> tasign <- paste("tList[[n]] <- try(summary(dtree[dtree$class02 ==
> paste(data$class02[n]) & dtree$class04 == paste(data$class04[n]) &
> dtree$PREDICT==paste(data$PREDICT[n]),]))")
> tasign <- parse(text=tasign)[[1]]
>
> for(n in 1:nrow(data)) {
> TAsign <- do.call("substitute",list(tasign,list(n=n,X=as.name(n))))
> eval(TAsign)
> }
So, why are you doing these complicated things?
Just using
names(theList) <- apply(data, 1, paste, collapse="")
(you want to replace data by the corrected name) after your loop in your
first version would be sufficient, if you are going to name the list
elements....
Uwe Ligges
>
>
>
> Am Sonntag, 16. Mai 2004 12:48 schrieb Uwe Ligges:
>
>>Christian Schulz wrote:
>>
>>> X <- numeric(length(data.frame))
>>>before the loop maybe work, because
>>>my computer works and works !?
>>>
>>>christian
>>>
>>>
>>>---------- Weitergeleitete Nachricht ----------
>>>
>>>Subject: filter out many data.frames
>>>Date: Sonntag, 16. Mai 2004 00:02
>>>From: Christian Schulz <ozric at web.de>
>>>To: r-help at stat.math.ethz.ch
>>>
>>>Hi ,
>>>
>>>i would like filter out all combinations of a data-mining result?
>>>How i have to declare X because in every loop step it have another
>>>lengths ?
>>>
>>> X <- numeric(length(i1,...,i64)) ?
>>>
>>>Many thanks
>>>Christian
>>>
>>>
>>> tres <- function(data.frame) {
>>>+ data <- expand.grid(class02 = c("A","B","C","D"), class04 =
>>>c("A","B","C","D"),PREDICT = c("A","B","C","D"))
>>>+ for (i in 1:nrow(data)){
>>>+ X[i]<- dtree[dtree$class02 == paste(data$class02[i]) &
>>>dtree$class04 == paste(data$class04[i]) &
>>>dtree$PREDICT==paste(data$PREDICT[i]),] + }
>>>+ return(X[i])
>>>+ }
>>
>>Eh. You really want to rewrite that code. It depends on objects
>>available in its parent (or grand-parent) envrionment.
>>I don't see why you need all those calls to paste().
>>You do *not* want to call an argument data.frame nor any other object
>>data, but you *do* want to use the arguments specified.
>>
>>Now, if X is initialized with numeric(), X is a numeric (n x 1) vector.
>>I think you need at least a matrix or better a list, if the subsetting
>>stuff returns more or even less than one row.
>>
>>For a list X use, e.g.,
>> X <- vector(nrow(data), mode = "list")
>>just before the for loop.
>>
>>Uwe Ligges
>>
>>
>>>>tres(dtree)
>>>
>>>Error: Object "X" not found
>>>
>>>______________________________________________
>>>R-help at stat.math.ethz.ch mailing list
>>>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>>>PLEASE do read the posting guide!
>>>http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list