[R] Help with apply and split...

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Fri May 2 13:01:35 CEST 2008


> datg=t(sapply(split(datgic, datgic$NPERMNO, drop=TRUE), 
function(x){return(
> x[nrow(x),] )}))
> 
> 
> I get something like this...
> 
>       GVKEY  NPERMNO GIC      year
> 10001 12994  10001   55102010 2007
> 10002 19049  10002   40101015 2007
> 10009 16739  10009   40101010 1999
> 
> Has this been made into a proper data frame.  How come the row numbers 
are
> not 1,2,3,4...?

You can check if a variable is a 'proper data frame' using 
is.data.frame(datg) or class(datg).

The row numbers are preserved from the original data frame to make it 
easier to check that you've extracted the correct rows.  You can renumber 
them using
rownames(datg) <- seq_len(nrow(datg))

Regards,
Richie.

Mathematical Sciences Unit
HSL


------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}



More information about the R-help mailing list