I have a matrix m
and a vector v
. The vector specifies which element I need in each of m
's columns. The length of v
equals the number of columns in m
. I tried apply(m,2, FUN)
but couldn't come up with the right function to do the trick. My data and vector are defined bellow.
set.seed(12)
m <- matrix(sample(1:100,28),4)
v <- c(3,2,2,3,1,4,3)
The result I want is a vector vv
:
vv <- c(93,4,1,23,39,82,85)
Help is greatly appreciated!