# Select column and row values with an index in data frame

<>This question already has an answer here:

## Answers

Since you have your indices in ind one way could be to use mapply:

#the first argument is the function call #second argument is your matrix coerced to data.frame #third argument is your indices #each time an index will be used in conjunction to a column #and you get your result mapply(function(x,y) x[y], as.data.frame(mat), ind) # LO3 Tx Gh RH SR # 0.4282915 0.4863608 -0.4962140 -0.8023141 -0.8023141

This can do it for you:

mapply(function(i,j) sample[i,j], seq_len(ncol(sample)), ind) > mapply(function(i,j) sample[i,j], seq_len(ncol(sample)), ind) [1] 0.4282915 0.4863608 -0.4962140 -0.8023141 -0.8023141

if you want you can set the names of the result from ind