Thanks jean.

 

From: Jean V Adams [via R]
[mailto:ml-node+s789695n4636289h97@n4.nabble.com] 
Sent: Thursday, July 12, 2012 6:14 PM
To: Akkara, Antony (GE Energy, Non-GE)
Subject: Re: Add row into a Matrix witout headers from Function

 

Try using the rbind() function to combine the two vectors from colSums()

into a matrix.  Then assign row names and get rid of column names using 
the dimnames() function.  For example: 

OLDMatrix <- matrix(c(22, 25, 10, 24, 27, 13, 23, 27, 15), 
        ncol=3, dimnames = list(NULL, c("X1", "X2", "X3"))) 

NEWMatrix <- rbind(colSums(OLDMatrix ), colSums(!is.na(OLDMatrix ))) 
dimnames(NEWMatrix) <- list(c("SUM", "COUNT"), NULL) 

OLDMatrix 
     X1 X2 X3 
[1,] 22 24 23 
[2,] 25 27 27 
[3,] 10 13 15 

NEWMatrix 
      [,1] [,2] [,3] 
SUM     57   64   65 
COUNT    3    3    3 

Jean 


Rantony <[hidden email]> wrote on 07/12/2012 12:22:53 AM: 


> Hi, 
> Here i have a matrix like this, 
> 
> OLDMatrix <- 
> X1         X2        X3 
> -----      ------    ------ 
> 22          24         23 
> 25          27         27 
> 10          13         15 
> 
> the thing is, 
> im running two function(SUM,COUNT) to get output in another matrix 

called 


> NEWMatrix 
> 
> NEWMatrix <- c("SUM",colSums(OLDMatrix )) 
> NEWMatrix  <- c("COUNT",colSums(!is.na(OLDMatrix ))) 
> 
> Actually i need to get output like this, 
> 
> NEWMatrix <- 
> 
> SUM      57       64         65 
> COUNT  3         3           3 
> 
> Instead of getting out put like above, new row getting replaced by new


row 
> of vales. 
> and after executing the function i getting the values with header. How

can i 
> insert row 
> of vales into NewMatrix without header. ? 
> 
> Can anyone please help me ? 
> Thanks & Regards, 
> -Antony 

        [[alternative HTML version deleted]] 

______________________________________________ 
[hidden email] 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. 



________________________________

If you reply to this email, your message will be added to the discussion
below:

http://r.789695.n4.nabble.com/Add-row-into-a-Matrix-witout-headers-from-
Function-tp4636256p4636289.html 

To unsubscribe from Add row into a Matrix witout headers from Function,
click here
<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscrib
e_by_code&node=4636256&code=YW50b255LmFra2FyYUBnZS5jb218NDYzNjI1NnwxNTUx
OTQzMDI5> .
NAML
<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_view
er&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.Bas
icNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.tem
plate.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml
-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemai
l.naml>  



--
View this message in context: http://r.789695.n4.nabble.com/Add-row-into-a-Matrix-witout-headers-from-Function-tp4636256p4636290.html
Sent from the R help mailing list archive at Nabble.com.
	[[alternative HTML version deleted]]

