Skip to content
Prev 299925 / 398503 Next

Add row into a Matrix witout headers from Function

Hi Jean,

If we convert the NEWMatrix to dataframe,then headers do appear. 


NewMatrix1<-data.frame(NewMatrix)
?NewMatrix1
???????????? X1 X2 X3 X4
SumMatrix?? SUM 57 64 65
CountMat? COUNT? 3? 3? 3

#assigning headers to NULL
?colnames(NewMatrix1)<-NULL
?NewMatrix1
???????????? NA NA NA NA
SumMatrix?? SUM 57 64 65
CountMat? COUNT? 3? 3? 3
names(NewMatrix1)

NULL

I guess then it will be better to store as matrix.

A.K.




----- Original Message -----
From: Jean V Adams <jvadams at usgs.gov>
To: Rantony <antony.akkara at ge.com>
Cc: r-help at r-project.org
Sent: Thursday, July 12, 2012 8:42 AM
Subject: Re: [R] 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 <antony.akkara at ge.com> wrote on 07/12/2012 12:22:53 AM:
called
row
can i
??? [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org 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.