Douglas Bates <[EMAIL PROTECTED]> writes:

> Ed L Cashin <[EMAIL PROTECTED]> writes:
...
>> I think I need to look at the source of split when I have more time.
>
> ?split is probably a better place to start.

I've read that, so I think I need more nitty gritty.

>> > [1] If you really want to be cautious you could use an octal
>> > representation like sep="\007" to get a character that is very
>> > unlikely to occur in a factor level.
>> 
>> I definitely want to be cautious.  Instead of the bell character I
>> think I'll use the field separator character, "\034", just because
>> this is the first time I've been able to use it for it's intended
>> purpose!  ;)
>
> Yes, but with "\034" you don't get to make obscure James Bond
> references :-).

I hadn't thought of that.

One thing I notice is that I get funny row names using this method.  I
can change them back easily enough, though.

> d
    a b  c
1   1 4 31
2   2 3 32
3   3 2 33
4   4 1 34
11  1 4 41
21  2 3 42
31  3 2 43
41  4 1 44
12 41 0  0
> d2 <- do.call("rbind",
          lapply(split(d,
                       factor(paste(d$a,
                                    d$b,
                                    sep = "\034"))),
                 function(x) x[x$c == min(x$c),]))
> d2
      a b  c
14   1 4 31
23   2 3 32
32   3 2 33
41   4 1 34
410 41 0  0
> row.names(d2) <- 1:nrow(d2)
> d2
   a b  c
1  1 4 31
2  2 3 32
3  3 2 33
4  4 1 34
5 41 0  0
> 

-- 
--Ed L Cashin            |   PGP public key:
  [EMAIL PROTECTED]        |   http://noserose.net/e/pgp/

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to