A example:
set.seed(123)
m <- matrix(rnorm(12), 3)
myParam <- rowMeans(m)
sweep(m, 1, myParam, FUN = "-")
This subtracts the myParam value in each column.
On Fri, Jan 29, 2010 at 6:59 PM, anna wrote:
>
> I had a quick look at the sweep function but didn't find a solution in it, I
> am going to
I had a quick look at the sweep function but didn't find a solution in it, I
am going to look at it again then.
-
Anna Lippel
--
View this message in context:
http://n4.nabble.com/Applying-a-function-on-each-columns-of-a-matrix-tp1415660p1428193.html
Sent from the R help mailing list archiv
See sweep function
On Fri, Jan 29, 2010 at 2:32 PM, anna wrote:
>
> Hello everyone, I have the following matrix
> [,1] [,2] [,3] [,4]
> [1,] 0.002809706 0.0063856960 0.0063856960 0.011749681
> [2,] 0.004893124 0.0023118418 -0.0005122951 -0.014646465
>
But then I would have to make a loop right?
-
Anna Lippel
--
View this message in context:
http://n4.nabble.com/Applying-a-function-on-each-columns-of-a-matrix-tp1415660p1415743.html
Sent from the R help mailing list archive at Nabble.com.
__
R-h
Hello,
You could do something along the following lines:
sapply( 1:ncol( my.matrix ),
function( i )
my.foo( my.matrix[,i], my.parm[i]
)
Best regards,
Carlos J. Gil Bellosta
http://www.datanalytics.com
anna wrote:
Hello everyone, I have the following matrix
Hello everyone, I have the following matrix
[,1] [,2] [,3] [,4]
[1,] 0.002809706 0.0063856960 0.0063856960 0.011749681
[2,] 0.004893124 0.0023118418 -0.0005122951 -0.014646465
[3,] 0.003547897 0.0063355297 0.0030410542 0.011403953
[4,] 0.004838
6 matches
Mail list logo