[R] Rbind for appending zoo objects

2007-01-30 Thread Shubha Vishwanath Karanth
Hi R,

 

y1 - zoo(matrix(1:10, ncol = 2), 1:5)

colnames(y1)=c(a,b)

y2 - zoo(matrix(rnorm(10), ncol = 2), 6:10)

colnames(y2)=c(b,a)

 

 y1

  a  b

1 1  6

2 2  7

3 3  8

4 4  9

5 5 10

 

 y2

b  a

6   0.9070204  0.3527630

7   1.2405943  0.8275001

8  -0.1690653 -0.1724976

9  -0.6905223 -1.1127670

10  0.3776210  0.4208908

 

Now, I have to append these two zoo objects, y1 and y2. So, I do as
follows:

 

 rbind(y2,y1)

b  a

1   1.000  6.000

2   2.000  7.000

3   3.000  8.000

4   4.000  9.000

5   5.000 10.000

6   0.9070204  0.3527630

7   1.2405943  0.8275001

8  -0.1690653 -0.1724976

9  -0.6905223 -1.1127670

10  0.3776210  0.4208908

 

 

The doubts I get are as follows:

1.  The above rbind function for the zoo objects doesn't take care
of the column names while merging. Example: Column 'a' of y1 is appended
with column 'b' of y2. Why is this so? How do I get rid of this?
2.  In the rbind function, I have given y2 first and then y1. But in
the appended data, I see the data corresponding to y1 first and then of
y2. Is this because of ordering of the index elements of the zoo
objects?

 

Or, is there any other better function to append zoo objects?

 

Thanks in advance,

Shubha 


[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.


Re: [R] Rbind for appending zoo objects

2007-01-30 Thread Achim Zeileis
On Tue, 30 Jan 2007, Shubha Vishwanath Karanth wrote:

 1.The above rbind function for the zoo objects doesn't take care
 of the column names while merging. Example: Column 'a' of y1 is appended
 with column 'b' of y2. Why is this so?

We do not check the column names at all. This should probably be changed.

 How do I get rid of this?

Sort the columns by hand before calling rbind().

 2.In the rbind function, I have given y2 first and then y1. But in
 the appended data, I see the data corresponding to y1 first and then of
 y2. Is this because of ordering of the index elements of the zoo
 objects?

Yes, recall that the second o in zoo means ordered.

Best,
Z

__
R-help@stat.math.ethz.ch 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.