From wdunlap at tibco.com  Mon Mar 21 17:16:46 2011
From: wdunlap at tibco.com (William Dunlap)
Date: Mon, 21 Mar 2011 09:16:46 -0700
Subject: [Rd] split(factor,
	shortGroupVector) gives incorrect results in R 2.12.2
Message-ID: <77EB52C6DD32BA4D87471DCD70C8D70004086330@NA-PA-VBE03.na.tibco.com>

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 



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