1 Jul 2010 01:22
Re: problem with rbind on data.frames that contain data.frames
Michael Lachmann <lachmann <at> eva.mpg.de>
2010-06-30 23:22:08 GMT
2010-06-30 23:22:08 GMT
On 30 Jun 2010, at 22:55, Allan Engelhardt wrote: >> > a$z=z > You are (kind of) assigning *two* columns from the data frame "z" to > the name 'z' in "a" which is probably not going to work as you > expect. R tries to be clever which may or may not be a Good Thing. > Try > > a$z1 <- z[,1] > a$z2 <- z[,2] Yes, the problem is that I wanted my code to work on data where the number of columns is variable. Of course even that can be handled.... just much uglier than just assigning the result of the computation to a part of the data.frame. I was mainly asking how I could have avoided having the bug in the first place... once I found it, it was easy to solve. I tried to track the problem further... As I said before, the problem is there if one does a=data.frame(1:10,1:10) a$z=a rbind(a,a) in this case str(a) gives: --- > str(a) 'data.frame': 10 obs. of 3 variables: $ X1.10 : int 1 2 3 4 5 6 7 8 9 10(Continue reading)
RSS Feed