user1723765
user1723765

Reputation: 6409

Using lapply() over a sequence of numbers

I would like to use lapply() in the following way:

I have a vector:

a<-c(1,4,6,8,9,10,11,12,14,19)
y<-1:10
lapply(a, function(x) othermatrix[othermatrix[,2,
    x] == somethingelse[y], 3, x])

The idea is to use the numbers specified in a instead of a usual sequence of consecutive numbers like 1:100. but use a sequence of consecutive numbers as y

How can this be done?

Upvotes: 0

Views: 1252

Answers (1)

Sven Hohenstein
Sven Hohenstein

Reputation: 81713

You can use mapply:

a<-c(1,4,6,8,9,10,11,12,14,19)
y<-1:10

mapply(function(x,y) othermatrix[othermatrix[, 2, x] == somethingelse[y], 3, x], 
       a, y)

The first argument is the function. The other arguments are the objects passed to the function.

Upvotes: 1

Related Questions