[R] order in lapply
Sundar Dorai-Raj
sundar.dorai-raj at pdf.com
Wed Jul 2 20:46:05 CEST 2003
Ernesto Jardim wrote:
> Hi
>
> When using "split" is it possible to keep then same ordering of the
> factor on the output list ?
>
> Thanks
>
> EJ
>
There may be an easier way to do this but I would make the split
variable ordered before calling split. As in:
> d = data.frame(a = 1:4, b = c("d", "c"))
> sapply(d, data.class)
a b
"numeric" "factor"
> split(d$a, d$b)
$c
[1] 2 4
$d
[1] 1 3
> d$b = ordered(d$b, c("d", "c"))
> sapply(d, data.class)
a b
"numeric" "ordered"
> split(d$a, d$b)
$d
[1] 1 3
$c
[1] 2 4
>
Regards,
Sundar
More information about the R-help
mailing list