Skip to content
Prev 246605 / 398506 Next

Extract data

On Jan 6, 2011, at 6:36 AM, Chris Mcowen wrote:

            
> tapply(comm.info$species, comm.info$community, c)
$AT1302
[1] 1 2

$NA0402
[1] 2 3

$NA1102
[1] 1 3

 > lapply( tapply(comm.info$species, comm.info$community, c),  
function(x){ sp.info[x, ]} )
$AT1302
   Species X1 X2 X3
1       a  t  y  h
2       b  f  j  u

$NA0402
   Species X1 X2 X3
2       b  f  j  u
3       c  r  y  u

$NA1102
   Species X1 X2 X3
1       a  t  y  h
3       c  r  y  u

Might have looked more compact if I had assigned the output of tapply  
to an intermediate list:

comm.sp <- tapply(comm.info$species, comm.info$community, c)
lapply( comm.sp , function(x){ sp.info[x, ]} )
David Winsemius, MD
West Hartford, CT