Part of the problem is that you are not adjusting for the fact that you
are smarter than the computer.

Realize that the way you are doing the assignment requires a lot of
different things behind the scenes and remember that data frames are
basically lists with some extra attributes and matricies are vectors
with some extra attributes.  

So in your case the left hand side of the assignment is a vector with 4
slots to fill and the right side is a list with 2 element that need to
be put into the 4 slots.

You realize that each of the 2 elements of the list have 2 elements for
a total of 4 and being the smart human that you are (assuming your not a
turing machine) you think, that is a total of 4 elements, one for each
slot.  But the computer is not smart and unless someone tells it to look
for this type of case and convert, it is not smart enough to do it on
its own and instead puts a list element into each slot of the vector
(changing it to a list in the process).  

Since the programmers of these routines did not anticipate you asking
the computer to do such things, you can tell the computer how you really
want the assignment to take place by turning the 4 numbers into
something the computer knows about.  Wrap the d[,1:2] in either
as.matrix or unlist and it does what I expect you expect it to do.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 
 

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
> Sent: Tuesday, February 19, 2008 5:50 AM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: [Rd] Assigning a sub-matrix from a data frame to a 
> regular matrixcauses strange behaviour (version 2.6.1) (PR#10799)
> 
> See below:
> 
>  
> 
> > d = data.frame(v1=1:2,v2=1:2)
> 
> > x = matrix(0,2,2)
> 
> > x[,1:2] = d[,1:2]
> 
> > x
> 
> [[1]]
> 
> [1] 1 2
> 
>  
> 
> [[2]]
> 
> [1] 1 2
> 
>  
> 
> [[3]]
> 
> [1] 1 2
> 
>  
> 
> [[4]]
> 
> [1] 1 2
> 
>  
> 
> > 
> 
>  
> 
> Thanks for all the work in R. Still love it.
> 
>  
> 
> David
> 
>  
> 
>  
> 
> David Lubinsky
> 
> Director
> 
> OPSI Systems
> 
>  
> 
> Phone:  +27 11 880 7951
> 
> Cell: +27 82 452 9556
> 
> URL:  <http://www.opsi.co.za> www.opsi.co.za
> 
> Email:  <mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED]
> 
>  
> 
> 
>       [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to