So you want mylist[[1:2]] to return something (other than an error) when mylist 
is a list.

What if mylist <- list( 1:10, 101:110 , some.other.things) so the first 2 
elements are vectors of length 10.  then mylist[1:2] makes sense as still being 
a list with the 2 vectors.  What should mylist[[1:2]] return in this case?  One 
vector of length 20? or should it return a matrix with 2 columns and 10 rows.  
Both of those make sense, how should the computer decide between them (it may 
be obvious to you knowing the context, but how can the computer decide).  You 
can do either of these in R by giving the computer a bit more information 
(as.matrix or unlist).  What if one of the vectors is character and one is 
numeric, what should the return object be?  What if the first element of mylist 
is the return object from "lm" and the second element is a function, what 
should mylist[[1:2]] return then?

If you can come up with a set of rules that will cover every possible case, 
then someone may be willing to implement those rules.  But while it is not 
obvious what to return without giving extra information, it is better to 
require the extra information through other functions.

 

 


________________________________

From: [EMAIL PROTECTED] on behalf of Olivier Lefevre
Sent: Sat 4/26/2008 9:43 AM
To: [EMAIL PROTECTED]
Subject: Re: [R] matrix from list



Olivier Lefevre wrote:
> Anyway you are right that it would still return the kind of object, only
> subsetted, which is not I want.

I mean [] would do that; I know [[]] doesn't. Yet I still don't see why one
accepts vector arguments but not the other: they are both indexing
operators. It is such inconsistencies that make languages hard to learn.

-- O.L.

______________________________________________
R-help@r-project.org 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.



        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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