Is this what you're looking for?

mymatrix = matrix(rnorm(15),5,3,dimnames=list(NULL,c('x','y','z')))
mymatrix
              x          y          z
[1,] -0.4459162 -2.3936837 -0.7401963
[2,]  0.9886466 -1.3955161 -1.3390314
[3,] -0.2086743  1.7984620 -0.8532579
[4,]  1.0985411  0.9315553 -1.3981632
[5,]  0.5787438  0.1719177  0.2246174
mymatrix[,'y'] = round(mymatrix[,'y'])
mymatrix
              x  y          z
[1,] -0.4459162 -2 -0.7401963
[2,]  0.9886466 -1 -1.3390314
[3,] -0.2086743  2 -0.8532579
[4,]  1.0985411  1 -1.3981632
[5,]  0.5787438  0  0.2246174


                                        - Phil Spector
                                         Statistical Computing Facility
                                         Department of Statistics
                                         UC Berkeley
                                         spec...@stat.berkeley.edu

On Mon, 22 Nov 2010, madr wrote:


round() function affects all values of a matrix, I want only to round column
that is called 'y'.
--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-round-only-one-column-of-a-matrix-tp3054363p3054363.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@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.


______________________________________________
R-help@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.

Reply via email to