[R] converting a for loop into a foreach loop

kalee kathryn.lee1 at students.mq.edu.au
Mon Jan 23 07:14:35 CET 2012

Thanks Jim for your reply. I've split the dataset into indices but am now
having problem with my function. The function I need to use is in two parts: 

> H.scv <- Hscv(idh, pilot = "unconstr") ## commands from the ks package
> KDE <- kde(idh, H=H.scv, approx.cont=TRUE) 

I've tried to write these as a function separately to be applied within the

myfun <- function(x){
H.scv <- Hscv(idh, pilot = "unconstr")
KDE <- kde(idh, H=H.scv, approx.cont=TRUE) 

HR <- sapply(idh, myfun)

However, the first part of my function (H.scv) doesn't recognise the idh
(when applied within the sappily or on its own). Is there anyway to write
the code so that it would recognise each indices? I.e ID = 1, day =1, hour
=0 so indices number is 1.1.0 and then H.scv would be Hscv(1.1.0, pilot =

Basically I need to be able to use the Hscv and kde test for each hour of
each day for each ID that I have and can't get the tests (functions) to
recognise the input at the moment (Hscv input must be a vector or matrix).


View this message in context: http://r.789695.n4.nabble.com/converting-a-for-loop-into-a-foreach-loop-tp4309646p4319971.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list