Skip to content

problem with merging two matrices

5 messages · flokke, Sarah Goslee

#
Dear all, 
I hope you can forgive me my stupid questions, but I am a very new R user (;

So, this is my question:

I have two matrices, 
those are:

matrix1 <- matrix(cbind(vector1, vector2), 1,2, dimnames = list(c("values"), 
                                                               c("T value",
"p value")))

matrix2 <- matrix(dcbind,2,6,dimnames = list(c("x", "y"),
                                  c("Min", "1st qu.", "Median", "Mean", "3rd
qu.", "Max")))

Now, I would like to merge them, but I want to receive the following result:

     Min 1st qu. Median Mean 3rd qu. Max
  x   3      3            4      4        4      4
  y   3       3           3      3         3     3 

       t value p value
value   3           3

so both vectors should stand above each other... 
when I use merge() I dont get this result, also not with cbind or rbind. 
I neither can make a a data frame of the two matrices. 
I think that I should use the function array with dim(6,2,2), but I dont
know how that is exactly working
(I couldn make it working)

I would be very glad if you could let me know how to solve this problem. 

Cheers, 
maria



--
View this message in context: http://r.789695.n4.nabble.com/problem-with-merging-two-matrices-tp3983136p3983136.html
Sent from the R help mailing list archive at Nabble.com.
#
Dear Sarah, 
THanks for your answer!
Sorry that my thread is somehow not clear, that's because I am not really
experienced with R and 
dont know yet how to put thinings in words..

I am not trying to work with them differently, I am just trying to print
them as the result of a 
function. But as the result() function does allow only one argument I have
to somehow merge these 
two matrcices. I know that I could use the list() function as well but I
wanted to have some nicer output than that, that's why I created these two
matrices. 

Want I want to get in the end is that can call my function(x,y) and then you
get the print 
of the two matrices, above each other. 


--
View this message in context: http://r.789695.n4.nabble.com/problem-with-merging-two-matrices-tp3983136p3986638.html
Sent from the R help mailing list archive at Nabble.com.
#
Hi,
On Thu, Nov 3, 2011 at 12:31 PM, flokke <flokke at live.de> wrote:
See, that would have been useful to know.

If you wish to return two such matrices, you need to use a list.

If you are determined that they appear in a particular way, you could
also print them from within the function, so that particular things
appear onscreen regardless of the way in which the results are
returned.

But, in that case, you may be better off reconsidering what your
actual objectives are, and whether separating form and function might
not be a more effective course.

Sarah