Corrected version. I forgot the the count had to change 'after' eif==1:
#Simulated data frame: year from 1990 to 2003, for 5 different ids, each
having one or two eif "events"
test<-data.frame(year=rep(1990:2003,5),id=gl(5,length(1990:2003)),
eif=as.vector(sapply(1:5,function(z){
a<-r
Here is yet another way of doing it (always the case in R):
#Simulated data frame: year from 1990 to 2003, for 5 different ids, each
having one or two eif "events"
test<-data.frame(year=rep(1990:2003,5),id=gl(5,length(1990:2003)),
eif=as.vector(sapply(1:5,function(z){
a<-rep(0,length(1
You might try the following function. First it identifies the last element in
each run, then the length of each run, then calls sequence() to generate the
within-run sequence numbers. my.sequence is a version of sequence that is more
efficient (less time, less memory) than sequence when there
That will teach me to post without a double-check.
On 09/05/09 3:11 PM, "Finak Greg" wrote:
Assuming the year column has complete data and doesn't skip a year, the
following should take care of 1)
#Simulated data frame: year from 1990 to 2003, for 5 different ids, each having
one or two eif "
Assuming the year column has complete data and doesn't skip a year, the
following should take care of 1)
#Simulated data frame: year from 1990 to 2003, for 5 different ids, each having
one or two eif "events"
test<-data.frame(year=rep(1990:2003,5),id=gl(5,length(1990:2003)),eif=as.vector(sapply(
Hi everyone,
Please forgive me if my question is simple and my code terrible, I'm new to
R. I am not looking for a ready-made answer, but I would really appreciate
it if someone could share conceptual hints for programming, or point me
toward an R function/package that could speed up my processin
6 matches
Mail list logo