[R] Working With Variables Having Different Lengths

David Winsemius dwinsemius at comcast.net
Mon Oct 24 18:28:05 CEST 2011


On Oct 24, 2011, at 12:10 PM, Rich Shepard wrote:

> On Mon, 24 Oct 2011, David Winsemius wrote:
>
>> The appearance of levels with all zeroes is probably because I  
>> didn't include drop.unused.levels = FALSE in the xtabs specification.
>
>  OK. Adding 'drop.unused.levels' does make a huge difference.

You could also have saved the subsetted data, applied `factor` to the  
subsetted column and then used `xtabs`.

temp <- subset(chemdata, <your subset criteria>, <your column  
selection>)
temp$param <- factor(temp$param)

(Now only levels that exist are in the temp version.)

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list