On 02-02-2013, at 17:38, Brett Robinson wrote:
> Hi
> I'm trying to set up a simulation problem without resorting to (m)any loops.
> I want to set entries in a data frame of zeros ('starts' in the code below)
> to 1 at certain points and the points have been randomly generated and stored
> in
Hello,
Try the following.
set.seed(4315)
ml <- data.frame(matrix(sample(1:50,80, replace=TRUE),20,4))
mm <- apply(ml, 2, cumsum)
s2 <- starts <- data.frame(matrix(0,600,4))
for (i in 1:4){
starts[,i][mm[,i]] <- 1
}
s2[] <- lapply(seq_len(ncol(mm)), function(i) {s2[,i][mm[,i]] <- 1; s2[
Hi,
Not sure this helps:
ml <- data.frame(matrix(sample(1:50,80, replace=TRUE),20,4))
mm <- apply(ml, 2, cumsum)
starts<- data.frame(matrix(0,600,4))
starts1<- data.frame(matrix(0,600,4))
for (i in 1:4){
starts1[,i][mm[,i]] <-1
}
starts2<-as.data.frame(do.call(cbind,lapply(1:4,function(i)
{star
Many thanks Dimitris.
On Mon, Jul 26, 2010 at 9:13 AM, Dimitris Rizopoulos <
d.rizopou...@erasmusmc.nl> wrote:
> have a look at function rollapply() from package zoo.
>
> I hope it helps.
>
> Best,
> Dimitris
>
>
> On 7/26/2010 8:28 AM, Raghu wrote:
>
>> Hi
>>
>> I have 3500 rows of data (say a s
have a look at function rollapply() from package zoo.
I hope it helps.
Best,
Dimitris
On 7/26/2010 8:28 AM, Raghu wrote:
Hi
I have 3500 rows of data (say a single column) in a vector. If I want to
compare every ith element with the simple average of the previous (i-5)
elements, then I could
5 matches
Mail list logo