On 2007-May-18  , at 18:21 , Gabor Grothendieck wrote:
> In particular, we can use "[" directly instead of subset.  This is the
> same as your function except for the line marked ### :
>
> myfun2 <- function() {
>       foo = data.frame(1:10,10:1)
>       foos = list(foo)
>       fooCollumn=2
>       cFoo = lapply(foos, "[", fooCollumn) ###
>       return(cFoo)
> }
> myfun2() # test
>
> On 5/18/07, Prof Brian Ripley <[EMAIL PROTECTED]> wrote:
>> You need to study carefully what the semantics of 'subset' are.  The
>> function body of myfun is not in the evaluation environment.  (The  
>> issue
>> is 'subset', not 'lapply': select is an *expression* and not a  
>> value.)
>>
>> Hint: using subset() programmatically is almost always a mistake.   
>> R's
>> subsetting function is '[': subset is a convenience wrapper.

Thank you very much. Indeed it is much better this way. I got used to  
subset for data.frames because [ does not work with negative named  
arguments while select does. E.g.:
        x[,-c("name1","name2")]
does not work while
        subset(x,select=-c("name1","name2"))
works (it eliminates columns named name1 and name 2 from x). But I  
guess in most cases an other syntax can achieve the same thing with  
[, like:
        x[,-which(names(x)%in%c("name1","name2"))]
it's just a little less clear.
Thanks again.

JiHO
---
http://jo.irisson.free.fr/

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to