On 02-02-2013, at 17:38, Brett Robinson brett.robin...@7dials.com 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
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 a
separate data.frame ('sl'), which has the same number of
(starts1)
identical(starts1,starts2)
#[1] TRUE
A.K.
- Original Message -
From: Brett Robinson brett.robin...@7dials.com
To: r-help@r-project.org r-help@r-project.org
Cc:
Sent: Saturday, February 2, 2013 11:38 AM
Subject: [R] vectorisation
Hi
I'm trying to set up a simulation problem
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[,i]})
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
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 write something like this:
for(i in 6:NROW(data)){
if(data[i] = mean(data[(i-5):i]) (counter[i]=1)}
}
Is it possible
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 single column) in
7 matches
Mail list logo