Thank you for all the useful comments on how to solve my problem
As a wrap up I did this in what might be called "traditional" way and
probably lost out
on a lot of splus features. Here is the final program and a small sample
of the data. Any comments for improvement, of better ways to do this
using splus, would be appreciated, purpose; be a better s programmer!!
data set is B in prog.
fips year cat. case
01001 1989 1 1
01001 1994 2 1
01001 1996 4 1
01001 1986 3 1
01001 1986 5 1
01003 1986 2 2
01003 1987 1 2
01003 1988 3 1
01003 1989 1 5
01003 1989 2 3
01003 1989 5 2
the cat. column is not important, i want to sum the cases for similar fips
and years.
which should give me a new data set where the cases are summed but
maintaining instances where the cases are not summed.
new data set will be smaller with case column being the following
case
1
1
1
2
2
2
1
10
the program i wrote is
i<-1
ctr<-B[i,4]
while (i<11)
{
if (B[i,1]==B[i+1,1] && B[i,2]==B[i,2])
{
ctr<-ctr+B[i+1,4]
}
else
{
print(ctr)
ctr<-B[i+1,4]
}
i<-i+1
}
print(ctr)
I pulled quite a bit of hair out to get this to finally work
cheers
jb
|