Dear R-Fans,

The more I work with matrices (e.g., data.frames) the more I think it would be helpful to have functions to apply (several!) mathematical and/or logical operators column- or row-wise in a matrix.

I know the function apply() and all its derivates (e.g., lapply) but I think this does not help for solving (e.g.) the following task:

assume there is a 3x3 matrix:

1    2    4
4    5    3
1    3    4

How do I find - for each column separately - the position of the column's minimum without using loop commands, i.e.:

I could extract each column in a loop and use something like:

for (loopColumn in 1 : 3){

extractedColumnVector  = myMatrix[, loopColumn]

position = which(extractedColumnVector == min (extractedColumnVector ) )

print(position)
}

I think that there should be something simpler out there to handle these kinds of tasks (maybe there is and I just don't know but I checked several R books and could not find a command to do this).

It would be great to have a function in which it is possible to define a sequence of commands that can be applied column/row-wise.

Thanks for a hint,

Marc

--
Dipl.-Psych. Marc Jekel

MPI for Research on Collective Goods
Kurt-Schumacher-Str. 10
D-53113 Bonn
Germany

email: je...@coll.mpg.de
phone: ++49 (0) 228 91416-852

http://www.coll.mpg.de/team/page/marc_jekel-0

______________________________________________
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