[R] Working With Variables Having Different Lengths

Rich Shepard rshepard at appl-ecosys.com
Mon Oct 24 17:34:07 CEST 2011


On Fri, 21 Oct 2011, David Winsemius wrote:

> The first thing I would try would be
> with(subset(chemdata, param %in% c('TDS', 'Cond', 'Mg', 'SO4', 'Cl', 'Na', 
> and 'Ca') , 1:4) ,
>    xtabs(quant ~ site + sampdate + param) )

David,

   Need to remove the 'and' from the above.

   The results include _all_ params, not just the six above and all sampdates
from 31 years ago. The first table begins with

, , param = AGP

                 sampdate
site             1981-11-30 1982-04-28 1982-05-24 1982-06-29 1983-10-20
   BC-0.5              0.000      0.000      0.000      0.000      0.000
   BC-1                0.000      0.000      0.000      0.000      0.000
   BC-1.5              0.000      0.000      0.000      0.000      0.000
   BC-2                0.000      0.000      0.000      0.000      0.000
   BC-3                0.000      0.000      0.000      0.000      0.000

and 20296 lines later (in emacs) that param ends and so does R's  [ reached
getOption("max.print") -- omitted 31 row(s) and 65 matrix slice(s) ].

   Why didn't the '%in%' limit the output to the specified params?

   Is the design of expressions such as the above based on your years of
experience with R or are such topics covered in a document somewhere? I have
bought almost a dozen R books in the past few months, have read most of
them, and don't recall seeing anything like the above.

Thanks,

Rich



More information about the R-help mailing list