Bug 15442 - combn treatment of factor variables
Summary: combn treatment of factor variables
Alias: None
Product: R
Classification: Unclassified
Component: Language (show other bugs)
Version: R 3.0.1
Hardware: x86_64/x64/amd64 (64-bit) All
: P5 enhancement
Assignee: R-core
Depends on:
Reported: 2013-09-04 15:46 UTC by Simon O'Hanlon
Modified: 2013-09-07 09:46 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Simon O'Hanlon 2013-09-04 15:46:48 UTC
For further discussion see: http://stackoverflow.com/q/18615939/1478381


x <- as.factor( letters[1:3] )
combn( x , 2 )
     [,1] [,2] [,3]
[1,] "a"  "1"  "2" 
[2,] "b"  "3"  "3" 

When simplify to array is set to TRUE, the level labels for the first combination are retained whilst they are dropped for the remaining combinations and the underlying integer codes are returned, but since this is a matrix all values are coerced to character values. When simplify = FALSE this behaviour does not occur.

R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)

[1] LC_COLLATE=English_United Kingdom.1252 
[2] LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] tools_3.0.1
Comment 1 Brian Ripley 2013-09-07 09:46:12 UTC
This is really misuse: x is not 'a vector source'.

Wish fulfilled for R-devel.