Apologies for asking a trivial question, but I'm stumped. Here's the situation:
fishCounter(data, x, y)
where data
is a matrix and both x and y are integers.fishCounter
is in memory and works completely fine when I call it manually (eg fishCounter(matrix(1:4,4,4), 1, 4)
). Its output is a single integer.trout
. fishCounter(trout, 3, 1:20)
.replicate
, apply
or lapply
will do this job.lapply(c(1:19), fishCounter(trout, 3, y)
didn't work.What have I forgotten?
Maybe you can try lapply
like below, ie,
lapply(1:20, function(y) fishCounter(trout, 3, y))
or Vectorize
over your function fishCounter
, ie,
Vectorize(fishCounter)(trout, 3, 1:20)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.