Greg.Snow at imail.org
2008-Feb-21 21:35 UTC
[Rd] Assigning a sub-matrix from a data frame to a regular (PR#10822)
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. =20 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). =20 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, --=20 Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org (801) 408-8111 =20 =20> -----Original Message----- > From: r-devel-bounces at r-project.org=20 > [mailto:r-devel-bounces at r-project.org] On Behalf Of david at opsi.co.za > Sent: Tuesday, February 19, 2008 5:50 AM > To: r-devel at stat.math.ethz.ch > Cc: R-bugs at biostat.ku.dk > Subject: [Rd] Assigning a sub-matrix from a data frame to a=20 > regular matrixcauses strange behaviour (version 2.6.1) (PR#10799) >=20 > See below: >=20 > =20 >=20 > > d =3D data.frame(v1=3D1:2,v2=3D1:2) >=20 > > x =3D matrix(0,2,2) >=20 > > x[,1:2] =3D d[,1:2] >=20 > > x >=20 > [[1]] >=20 > [1] 1 2 >=20 > =20 >=20 > [[2]] >=20 > [1] 1 2 >=20 > =20 >=20 > [[3]] >=20 > [1] 1 2 >=20 > =20 >=20 > [[4]] >=20 > [1] 1 2 >=20 > =20 >=20 > >=20 >=20 > =20 >=20 > Thanks for all the work in R. Still love it. >=20 > =20 >=20 > David >=20 > =20 >=20 > =20 >=20 > David Lubinsky >=20 > Director >=20 > OPSI Systems >=20 > =20 >=20 > Phone: +27 11 880 7951 >=20 > Cell: +27 82 452 9556 >=20 > URL: <http://www.opsi.co.za> www.opsi.co.za >=20 > Email: <mailto:david at opsi.co.za> david at opsi.co.za >=20 > =20 >=20 >=20 > [[alternative HTML version deleted]] >=20 > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >=20