[Rd] split(factor, shortGroupVector) gives incorrect results in R 2.12.2

From: William Dunlap <wdunlap_at_tibco.com>
Date: Mon, 21 Mar 2011 09:16:46 -0700


When split's x argument has a class attribute and the grouping vector, f, is shorter than x then split gives the wrong result. It appears to not extend f to the length of x before doing the split. E.g.,

> split(factor(letters[1:3]), "Group one") # expect all 3 elements in
the single group

   $`Group one`
   [1] a
   Levels: a b c
> split(factor(letters[1:3]), c("Group one", "Group two")) # expect
warning and Group one should contain "a" and "c".

   $`Group one`
   [1] a
   Levels: a b c

   $`Group two`
   [1] b
   Levels: a b c
We expect the above to act like the similar cases where x is a character vector

> split(letters[1:3], "Group one")

   $`Group one`
   [1] "a" "b" "c"

> split(letters[1:3], c("Group one", "Group two"))
   $`Group one`
   [1] "a" "c"

   $`Group two`
   [1] "b"

   Warning message:
   In split.default(letters[1:3], c("Group one", "Group two")) :      data length is not a multiple of split variable

We get a similar problem for other stray classes of x

> split(structure(letters[1:3],class="no sUch cLaSs"), c("Group one",
"Group two"))

   $`Group one`
   [1] "a"  

   $`Group two`
   [1] "b"

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 21 Mar 2011 - 16:19:41 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 21 Mar 2011 - 23:00:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive